在Rails Mailer主题行中包含ERB

时间:2012-07-07 21:50:46

标签: ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-3.1 actionmailer

我想在我的rails邮件的主题行中包含以下代码,但无法使其工作。这是什么正确的语法?谢谢!

<%= @occasions.map{|o|o.pname+"'s "+o.name}.to_sentence %>

邮件程序:

  def upcoming_deals_mail(user)

    @user = user
    @occasions = user.upcoming_occasions_with_deals
    @deals = user.upcoming_deals


    @subject = "An friendly Reminder"

    mail(:to => "#{ user.email } <#{ user.email }>", :subject => @subject)
  end

2 个答案:

答案 0 :(得分:3)

添加双引号(“”)而不是单引号('')为我做了

故障:

mail(to: 'test@email.com', subject: 'Application for: #{@applicant.full_name}')

成功:

mail(to: 'test@email.com', subject: "Application for: #{@applicant.full_name}")

答案 1 :(得分:0)

我不确定我是否理解你,但如果您想要做的只是在邮件主题中包含指定的ruby表达式,则可以用

替换@subject = "An friendly Reminder"
@subject = @occasions.map{|o|o.pname+"'s "+o.name}.to_sentence