2012-11-20 36 views
0

当用户的电子邮件输入忘记的密码表单并提交时,我收到一个错误,说login can't be blank。我看了一下devise.en.yml这个错误信息,但似乎无法在任何地方找到它。设计密码重置问题(new_user?)

这里是我的views/devise/passwords/new.html.haml

%div.registration_page 
    %h2 Forgot your password? 
    = form_for(resource, :as => resource_name, :url => user_password_path, :html => { :method => :post, :id => 'forgot_pw_form', :class => 'forgot_pw' }) do |f| 
    %div 
     = f.email_field :email, :placeholder => 'Email', :autofocus => true, :autocomplete => 'off' 
     %div.email_error.error 
    %input.btn.btn-success{:type => 'submit', :value => 'Send Instructions'} 
    = render "devise/shared/links" 

的形式张贴到users/password像它应该的,但我发现我忘记密码的形式附着class = 'new_user'。这里是我的表单显示:

<form accept-charset='UTF-8' action='/users/password' class='new_user' id='forgot_pw_form' method='post' novalidate='novalidate'></form> 

我对色器件的路线(我有自定义会话和注册控制器):

devise_for :users, :controllers => {:sessions => 'sessions', :registrations => 'registrations'} 

我怎样才能设置色器件的忘记密码功能?为什么我收到这个错误消息,为什么这个类被添加到那里?

我已经试过:

  • 添加我自己的密码控制器和我的自定义控制器添加新的路线。相同的错误
  • 将我自己的类和id添加到表单中。这成功地更改了窗体的ID和类别,但返回到类和ID new_user

谢谢。

回答

2

我有这个问题也。我错过了_method标记,以便它被路由到密码#创建的,而不是密码#更新

如果是同一个问题,按照你的表格将让你去:

<input type="hidden" name="_method" value="put" />

+0

这是我的问题。谢谢! – iHiD

2

我觉得你的主要问题可以是下列之一:

1)您的路线看起来不正确设置它应该是这个样子

devise_for :users, :controllers => {:sessions => 'devise/sessions', :registrations => 'devise/registrations', :passwords => 'devise/passwords'}, :skip => [:sessions] do 

2)你密码/ new.html.erb看起来有点不正确试试这个:

<h2>Forgot your password?</h2> 

<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post }) do |f| %> 
    <%= devise_error_messages! %> 

    <div><%= f.label :email %><br /> 
    <%= f.email_field :email %></div> 

    <div><%= f.submit "Send me reset password instructions" %></div> 
<% end %> 

<%= render "devise/shared/links" %> 

3)内,您的你的config /环境/ development.rb内做FOL降脂:

Development.rb

#Defined SMTP options 
    #config.action_mailer.default_url_options = { :host => "77.100.90.77:3000" 
    #SMTP 
    config.action_mailer.default_url_options = { :host => 'localhost:3000/' } 
    config.action_mailer.delivery_method = :smtp 
    config.action_mailer.smtp_settings = { 
     :address    => 'smtp.gmail.com', 
     :port     => 587, 
     :domain    => 'gmail.com', 
     :user_name   => '*****@gmail.com', 
     :password    => 'PASS', 
     :authentication  => 'login', 
     :enable_starttls_auto => true 
    } 

你可以看到从这个设置我使用Gmail进行测试。遵循我提供的内容应该可以解决您的问题。让我知道这个是否奏效。

更新

会假定authentication_keys设置:用户名作为必填字段。

尝试编辑app/views/devise/passwords/new.html。雇员再培训局,并替换:

<%= f.label :email %> 
<br /> 
<%= f.text_field :email %> 

有:

<%= f.label :username %> 
<br /> 
<%= f.text_field :username %> 
+0

我的路线似乎设置正确。我有自定义'session'和'registration'控制器(分别命名为'sessions_controller.rb'和'registrations_controller.rb')。我的smtp选项也设置完全像您指定的。当我在表单中输入一个电子邮件时,我收到一条警告:“登录不能为空。”我不知道为什么只有输入元素是电子邮件字段时才会弹出此错误。 –

+0

我已经更新了我的回答 – David

+0

您是否还检查过initaliziers/devise.rb,您已经启用了'config.authentication_keys = [:email]' – David