错号arg的对色器件电子邮件(wrong number of arg for devise emai

2019-10-17 17:39发布

我以前还没有遇到过,但因为我的移动轨道站点的Heroku我已经得到每当试图触发设计发送电子邮件以下信息

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

Answer 1:

看来最新版本需要一个额外的参数。
至少它为我的代码。 下面是我的自定义邮件类的工作代码。
请注意额外的参数action每种方法。

  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


Answer 2:

尝试这种方式,因为“设计在最近的版本中引入一个额外的参数选项”如上面提到的答案

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


Answer 3:

这是由于设计在最近的版本中引入一个额外的参数选项。 我想你想是这样的:

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


Answer 4:

结束了卸载的宝石,并重新安装似乎解决它:S



文章来源: wrong number of arg for devise emails