如何在Rails中的确认电子邮件中传递选项哈希中的额外参数?

我试图在确认电子邮件中的选项{}哈希中传递额外的参数,但它只显示主题和邮件中的标题。 这是我的代码

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 

为什么它不起作用?

不是一个完整的答案,但评论部分让我烦恼,尝试:

 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,它应该为您提供参与方法调用的参数。