【问题标题】:Devise forgot password throws ArgumentError in Devise::PasswordsController#create设计忘记密码在 Devise::PasswordsController#create 中引发 ArgumentError
【发布时间】:2013-05-12 17:10:51
【问题描述】:

最初,我只在我的 heroku 应用程序上遇到此问题,但在将设计 gem 更新到 2.2.4 后,我的本地主机上也遇到了问题。

我主要担心的是我收到了这个错误:

ArgumentError (wrong number of arguments (2 for 1)):
app/mailers/user_mailer.rb:58:in `reset_password_instructions'

我已将设计 gem 更新为

devise (2.2.4) 

我正在跑步:

Rails 3.2.11

我的 development.rb 初始化程序有以下主机:

config.action_mailer.default_url_options = { :host => 'localhost:3000' }

这是我的 user_mailer.rb 文件中第 58 行开始的地方:

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

我的问题是,为什么我要发送两个参数?它应该只在我的 devise/passwords/new.html.erb 文件中定义的电子邮件地址中发送:

<div class="container">
  <%= form_for(resource, :html => {:class => "form-signin", :method => :post}, :as => resource_name, :url => password_path(resource_name)) do |f| %>
    <h2 class = "form-signin-heading">Forgot your password?</h2>
    <%= devise_error_messages! %>
    <%= f.email_field :email, :type => "text", :class =>"input-block-level", :placeholder => "Email Address" %>
    <%= f.submit "Send me reset password instructions", :class => "btn btn-large btn-primary" %>
    </br>
    </br>
    <%= render "devise/shared/links" %>
  <% end %>
</div>

编辑: 我的 reset_password_instructions.html.erb 文件在这里:

<p>Hello <%= @resource.email %>!</p>
<p>Someone has requested a link to change your password, and you can do this through the link below.</p>
<p><%= link_to 'Change my password', edit_password_url(@resource, :reset_password_token =>@resource.reset_password_token) %></p>
<p>If you didn't request this, please ignore this email.</p>
<p>Your password won't change until you access the link above and create a new one.</p>

谁能发现问题?

【问题讨论】:

  • 您有views/user_mailer/reset_password_instructions.html.erb 模板吗?
  • d_ethier,刚刚添加了reset_password_instructions.html.erb文件

标签: ruby-on-rails devise


【解决方案1】:

看起来答案很简单,我必须按照设计的升级说明进行操作。对于遇到此问题的任何人,可以在 Devise 2.2 upgrade instructions 上找到对 Devise 2.2 的升级

编辑:

Devise 的升级文档包括使用选项块修改方法的说明。要解决此问题,您需要重新定义reset_password_instructions 方法,如下所示(注意,默认使用record 代替user,但此特定示例使用user):

def reset_password_instructions(user, opts={})
  ...
end

【讨论】:

  • 我假设它是def reset_password_instructions(user, opts={})。通常最好包含答案而不是指南链接。感谢您的更新。
  • 是的,就是这样。你介意用它来编辑答案,这样你也能获得荣誉。
猜你喜欢
  • 2012-09-24
  • 2015-04-06
  • 1970-01-01
  • 2018-09-09
  • 2013-10-20
  • 2012-01-07
  • 1970-01-01
  • 2017-04-07
  • 1970-01-01
相关资源
最近更新 更多