I am using custom mailer by overriding the devise mailer. It is working fine. But I need to pass some data to the mailer template so that when the confirmation email send to the user it contains some dynamic content. I have tried it using sessions,@resource and current_user method but both are not working. Is there any way to do that? Custom mailer
class CustomMailer < Devise::Mailer
helper :application # gives access to all helpers defined within `application_helper`.
include Devise::Controllers::UrlHelpers # Optional. eg. `confirmation_url`
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@abc.com'
@data = opts[:custom_field]
super
end
end
in the controller
CustomMailer.confirmation_instructions(token, {custom_field: "abc"})
This is the code in template
We are happy to invite you as user of the <b> <%= @data %> </b>
Thanks.