如何在Rails的确认电子邮件中的选项哈希内传递额外的参数? [英] How to pass extra params inside option hash in confirmation email in Rails?
本文介绍了如何在Rails的确认电子邮件中的选项哈希内传递额外的参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在确认电子邮件中的options {}哈希内传递额外的参数,但这只是向我显示主题和邮件标题中的内容。
这是我的代码
I am trying to pass extra params inside the options{} hash in the confirmation email but It is just showing me subject and from headers in the mailer. This is my code
CustomMailer.confirmation_instructions(user,token, {custom_param: "abc"})
当我在这样的模板中显示opts数据时
When I show opts data inside template like this
@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
为什么不起作用?
推荐答案
不是完整的答案,但评论部分让我很烦,请尝试:
Not a complete answer but the comments section was annoying me, try:
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
然后在您的邮件中e调用@first_name,然后调用@opts,它应该为您提供输入到方法调用中的参数。
Then in your mailer, where you were calling @first_name, call @opts and it should give you the argument you feed into the method call.
这篇关于如何在Rails的确认电子邮件中的选项哈希内传递额外的参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文