Trip
Trip

Reputation: 27114

Rails - How do I run a loop inside of a mailer?

So it turns out mailers hate loop inside of them. So here's my loop.

- for ["love", "hate", "war"].each do |f|
  = f

Which returns this went sent through actionmailer in rails 2.3.5 :

promotion_reminder.html.haml:17: syntax error, unexpected ';', expecting tCOLON2 or '[' or '.'
...ry_temp));}\n", 0, false);end;_hamlout.push_text("      </di...

On line #17 of app/views/notifier/promotion_reminder.html.haml

14:         
15:         - for ["love", "hate", "war"].each do |f|
16:           = f

How would you accomplish this?

Upvotes: 0

Views: 536

Answers (3)

jdl
jdl

Reputation: 17790

- ["love", "hate", "war"].each do |f|
  = f

Upvotes: 1

klew
klew

Reputation: 14967

Problem is with using both for and each. Try this:

- ["love", "hate", "war"].each do |f|
  = f

or this:

- for f in ["love", "hate", "war"] do
  = f

I don't use haml. Does it need end to close block?

Upvotes: 2

Jed Schneider
Jed Schneider

Reputation: 14671

try

- ["love", "hate", "war"].each do |f|
  = f

and watch your white sapce

Upvotes: 1

Related Questions