我试图让用户提交一个向另一个用户发送电子邮件的表单。一切都运行正常,除了我试图将电子邮件的正文存储在一个变量中,以显示在邮件的视图中,我得到'nil'。我设置了一个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}代替主题行,文本将呈现正常。
任何人都有任何线索发生了什么?
答案 0 :(得分:1)
@ user如何显示?可能是@body被rails使用,请尝试重命名。