Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'array.each do |block|' including results of statement in generated Haml HTML

Tags:

ruby

haml

I am generating an email with dynamic content from a Haml template which parses info from an array.

Basically, the Haml receives an array filled with several hashes. In the code I have a block which looks like this:

%table 
  =arrayname.each do |object|
    %tr
      %td= object.name
      %td= object.link

Whenever the email is sent the entire object arrayname is included at the bottom of the HTML. This causes [#,#] (more # when there are more objects) to show up at the top of the block. There is no way to manipulate this piece of text with CSS, else I would've just hidden it.

[#<Release @id=181 @title="test" @amurl="test.com" @iturl="test.com" @cover="test.com" @date="2012-03-28" @artist_name="Test">, #<Release @id=182 @title="test" @amurl="test.com" @iturl="test.com" @cover="" @date="2012-03-31" @artist_name="Test">]

The line is identical to the results shown when executing the code in IRB.

Can anyone tell me how to prevent this from happening?

like image 709
gagootch Avatar asked Mar 30 '12 23:03

gagootch


1 Answers

With Haml, you don't need to use an = for arrayname.each because that's Ruby code you want run, but not displayed. To just run code, use a hyphen.

Instead, this should work:

%table 
  - arrayname.each do |object|
    %tr
      %td= object.name
      %td= object.link
like image 185
kafuchau Avatar answered Oct 21 '22 16:10

kafuchau