我试图让用户提交一个向另一个用户发送电子邮件的表单。一切工作正常,除了我试图将电子邮件正文存储在一个变量中以显示在邮件程序的视图中并且得到“零”。我设置了一个 user_mailer.rb:
class UserMailer < ActionMailer::Base
default :from => "myemail@gmail.com"
def message_user(user, recipient, subject, body)
@user = user
@recipient = recipient
@body = "#{body}"
mail(:to => "#{recipient.name} <#{recipient.email}>", :subject => "Reelify message: #{subject}" )
end
end
这是我的 messages_controller.rb :
def new
@user = current_user
if !params[:receiver].blank? and !params[:subject].blank? and !params[:body].blank?
@recipient = User.find_by_name(params[:receiver])
UserMailer.message_user(@user, @recipient, params[:subject], params[:body]).deliver
flash[:notice] = "This flash means it should work.. #{@user.name} #{@recipient.name}"
end
结尾
当我在视图中调用@body 时,它是空白的(@body.inspect)导致'nil'。但是,如果我执行以下操作:#{body} 代替主题行,文本将呈现良好。
有人知道发生了什么吗?