How to pass extra params inside option hash in confirmation email in Rails?

寵の児 提交于 2020-01-06 09:57:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!