mailer.rb文件语法失败

时间:2013-06-11 10:08:54

标签: ruby-on-rails actionmailer

为什么这个方法产生一个空变量,因此是空体?

custom_email.text.erb

<%=@message%>

user_mailer.rb

default from: "Name <name@domain.com>"
def custom_email(email, subject, message)
  mail to: email, subject: "Name || #{subject}"
  @message = message
end

虽然这种方法有效:

mail to: email, subject: "Name || #{subject}", body: message

1 个答案:

答案 0 :(得分:1)

写这个

default from: "Name <name@domain.com>"
def custom_email(email, subject, message)
  @message = message
  mail to: email, subject: "Name || #{subject}"
end

而不是

default from: "Name <name@domain.com>"
def custom_email(email, subject, message)
  mail to: email, subject: "Name || #{subject}"
  @message = message
end

然后会考虑@message