开发者

HAML renders array after #each

I have the following HAML written to take the place of a scaffold index page:

%h1 Listing Races

%table
  %tr
    %th Name
    %th Date
    %th Details
  ~@races.each do |race|
    %tr
      %td= race.name
      %td= race.date
      %td= race.details
      %td= link_to 'Show', race
      %td= link_to 'Edit', edit_race_path(race)
      %td= link_to 'Destroy', race, :confirm => 'Are you sure?', :method => :delete
%br
= link_to 'New Race', new_race_path

When the page is rendered, the tables print out as expected, but afterwards, the array @races is printed as well; for example:

[#<Race id: 1, name: "Test开发者_Python百科Race15", date: "2011-03-11 11:00:00", details: "Test Race to make sure that everything seems to wor...", created_at: "2011-03-03 00:16:09", updated_at: "2011-03-03 00:16:09">]

Am I doing something incorrectly with the loop structure in the HAML, or what would be causing the array to be rendered?


The tilde (~) outputs the result of the line, which is an array, since Array#each returns the original array. = and ~ act similarly in that sense; ~, however, preserves whitespace that = usually strips.

You probably meant to use the dash (-), which runs the code but does not output the result of the expression.

See the HAML docs for more :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜