问题
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"})
When I show opts data inside template like this
@first_name = opts
It shows
{:subject=>"Email Confirmation", :from=>"no-reply@sample.com"}
custom mailer code is
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
why it is not working?
回答1:
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
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.
来源:https://stackoverflow.com/questions/48868508/how-to-pass-extra-params-inside-option-hash-in-confirmation-email-in-rails