Ruby on rails 为什么我的action mailer';中没有设置我的实例变量;你的观点是什么?
由于某些原因,此ActionMailer中未设置我的实例变量。其他ActionMailer似乎工作正常。你知道这是什么原因吗?UserMailer是一个限定词perpahps吗 使用rails 3.1Ruby on rails 为什么我的action mailer';中没有设置我的实例变量;你的观点是什么?,ruby-on-rails,view,actionmailer,instance-variables,Ruby On Rails,View,Actionmailer,Instance Variables,由于某些原因,此ActionMailer中未设置我的实例变量。其他ActionMailer似乎工作正常。你知道这是什么原因吗?UserMailer是一个限定词perpahps吗 使用rails 3.1 # app/mailers/user_mailer.rb class UserMailer < ActionMailer::Base default from: 'My Name <myname@example.com>' def registration_confi
# app/mailers/user_mailer.rb
class UserMailer < ActionMailer::Base
default from: 'My Name <myname@example.com>'
def registration_confirmation(user)
# Don't send email if we don't have an email address to send it to or the user is already confirmed
return unless user and user.email and not user.confirmed_at
# Set global variable for mail view
@my_message = 'Hello world!'
# Send email
mail(to: "#{user.name} <#{user.email}>", subject: 'Please confirm your email address')
end
end
# app/views/user_mailer/registration_confirmation.text.erb
Hello who? <%= @my_message %> # Simply returns 'Hello who? '
#app/mailers/user_mailer.rb
类UserMailer
结果是这一行:
return unless user and user.email and not user.confirmed_at
未中止发送电子邮件。相反,它只是中止上面看到的UserMailer代码,直接进入视图,该视图现在引用了一个尚未设置的实例变量。所以本质上,ActionMailer的工作原理与常规控制器完全相同
为了解决这个问题,我移动了检查是否将电子邮件发送到我运行UserMailer命令的位置的条件。结果是这一行:
return unless user and user.email and not user.confirmed_at
未中止发送电子邮件。相反,它只是中止上面看到的UserMailer代码,直接进入视图,该视图现在引用了一个尚未设置的实例变量。所以本质上,ActionMailer的工作原理与常规控制器完全相同
为了解决这个问题,我移动了检查是否将电子邮件发送到我运行UserMailer命令的位置的条件。如果要反映更改,您必须重新启动服务和工作程序。如果要反映更改,您必须重新启动服务和工作程序