我正在尝试在确认电子邮件中的选项{}哈希中传递额外的参数,但它只显示主题和邮件中的标题。 这是我的代码
CustomMailer.confirmation_instructions(user,token, {custom_param: "abc"})
当我在模板中显示opts数据时,就像这样
@first_name = opts
显示
{:subject=>"Email Confirmation", :from=>"no-reply@sample.com"}
自定义邮件程序代码
class CustomMailer < Devise::Mailer
helper :application # gives access to all helpers defined within `application_helper`.
include Devise::Controllers::UrlHelpers # Optional. eg. `confirmation_url`
#include ApplicationHelper
default template_path: 'devise/mailer' # to make sure that you mailer uses the devise views
def confirmation_instructions(record, token, opts={})
opts[:subject] = "Email Confirmation"
opts[:from] = 'no-reply@sample.com'
if(record["admin"]==false)
@template_type = 'donor'
@first_name = opts
end
end
为什么它不起作用?
答案 0 :(得分:0)
不是一个完整的答案,但评论部分让我烦恼,试试:
def confirmation_instructions(record, token, opts={})
@opts = opts
opts[:subject] = "Email Confirmation"
opts[:from] = 'no-reply@sample.com'
if(record["admin"]==false)
@template_type = 'donor'
@first_name = opts
end
end
然后在您调用@first_name的邮件程序中,调用@opts,它应该为您提供参与方法调用的参数。