wrong number of arg for devise emails

你离开我真会死。 提交于 2019-12-11 12:09:28

问题


I havent experienced this before, but since moving my rails site to Heroku I have getting the following message whenever trying to trigger Devise to send an email

Started POST "/members/forgot-password" for 127.0.0.1 at 2013-02-24 00:02:27 +1100
Processing by Devise::PasswordsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"9G1P34ddbq2TN7SkmFuCet5d7fPMvWdSSpIaGqSZW9g=", "user"=>{"email"=>"paul.mcguane@*****"}, "commit"=>"Recover password"}
  User Load (3.1ms)  SELECT "users".* FROM "users" WHERE "users"."email" = 'paul.mcguane@me.com' LIMIT 1
Completed 500 Internal Server Error in 31ms

ArgumentError - wrong number of arguments (2 for 1):
  app/mailers/devise/mailer.rb:8:in `reset_password_instructions'

mailer.rb

    class Devise::Mailer < ::ActionMailer::Base
  include Devise::Mailers::Helpers

  def confirmation_instructions(record)
    devise_mail(record, :confirmation_instructions)
  end

  def reset_password_instructions(record)
    devise_mail(record, :reset_password_instructions)
  end

  def unlock_instructions(record)
    devise_mail(record, :unlock_instructions)
  end
end

回答1:


It seems the latest version requires an additional argument.
At least it does for my code. Here's the working code from my custom mailer class.
Note the extra argument action for each method.

  class MyMailer < ActionMailer::Base

    include Devise::Mailers::Helpers

    def confirmation_instructions(record, token, opts={})
      @token = token
      devise_mail(record, :confirmation_instructions, opts)
    end

    def reset_password_instructions(record, token, opts={})
      @token = token
      devise_mail(record, :reset_password_instructions, opts)
    end

    def unlock_instructions(record, token, opts={})
      @token = token
      devise_mail(record, :unlock_instructions, opts)
    end

    # optional: this override method is from Devise::Mailers::Helpers
    def headers_for(action,opts={})
      …
    end

  end



回答2:


try this way, because 'Devise introducing an extra options parameter in a recent version' as mentioned in above answer

     def reset_password_instructions(record, opts={})
       devise_mail(record, :reset_password_instructions)
     end



回答3:


This is due to Devise introducing an extra options parameter in a recent version. I think you want something like:

class Devise::Mailer < ::ActionMailer::Base
  include Devise::Mailers::Helpers

  def confirmation_instructions(record, opts={})
    devise_mail(record, :confirmation_instructions, opts={})
  end

  def reset_password_instructions(record)
    devise_mail(record, :reset_password_instructions, opts={})
  end

  def unlock_instructions(record)
    devise_mail(record, :unlock_instructions, opts={})
  end

  def headers_for(actions, opts={}
    # see http://stackoverflow.com/a/14698599/18706
  end

end



回答4:


ended up uninstalling the gem, and reinstalling seemed to fix it :S



来源:https://stackoverflow.com/questions/15040844/wrong-number-of-arg-for-devise-emails

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