Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HAML renders array after #each

Tags:

haml

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
  [email protected] 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: "TestRace15", 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?

like image 350
ballpointcarrot Avatar asked Dec 09 '22 10:12

ballpointcarrot


1 Answers

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 :)

like image 144
Matchu Avatar answered Apr 25 '23 12:04

Matchu