2014-07-25 112 views
0

嗨,大家好, 我使用github和Rails 4.1.4的设计源。设计3.2.4使用设计/密码控制器中的更新方法“忘记我的密码”链接

我的Gemfile:

gem 'rails', '4.1.4' 
gem 'devise', path: '../devise' 

和我的色器件密码/ new.html.erb观点:

<%= simple_form_for(resource, as: resource_name, url: password_path(resource_name), method: :put) do |f| %> 
    <%= f.input :email %> 
    <%= f.button :submit, t('.send_me_reset_password_instructions' 
    , :default => "Send me reset password instructions") 
    , class: 'btn-primary pull-right', method: "post" %>  
<% end %> 

我北医三院方法: “后” 来试试强制创建方法

My config/routes.rb:

devise_for :users, controllers: 
{ omniauth_callbacks: "users/omniauth_callbacks" }, skip: :registrations 

devise_scope :user do 
    resource :registration, 
     only: [:new, :create, :edit, :update], 
     path: 'users', 
     path_names: { new: 'sign_up' }, 
     controller: 'devise/registrations', 
     as: :user_registration 
end 

条我的色器件路线:

 user_password POST  /users/password(.:format)    devise/passwords#create 
    new_user_password GET  /users/password/new(.:format)   devise/passwords#new 
edit_user_password GET  /users/password/edit(.:format)   devise/passwords#edit 

设计生成html形式:

<form accept-charset="UTF-8" action="https://stackoverflow.com/users/password" class="simple_form new_user" id="new_user" method="post" novalidate="novalidate"> 
..... 
</form> 

但是,当我点击提交按钮,我送到控制器中的更新(PUT)方法。我想,我需要重定向到创建(POST)方法。

Started PUT "https://stackoverflow.com/users/password" for 127.0.0.1 at 2014-07-25 12:07:05 -0300 
Processing by Devise::PasswordsController#update as HTML 
    Parameters: {"utf8"=>"✓", "authenticity_token"=>"gYiLxMKPSvCN5x6n5b0TtNyzTPcH1L3825Jp7NAdzs0=", "user"=> {"email"=>"[email protected]"}, "commit"=>"Enviar instruções para redefinição da senha"} 
gem install awesome_print # <-- highly recommended 

From: /home/carlos.ribeiro/code/devise/app/controllers/devise/passwords_controller.rb @ line 32 Devise::PasswordsController#update: 

    31: def update 
=> 32: binding.pry 
    33: self.resource = resource_class.reset_password_by_token(resource_params) 
    34: yield resource if block_given? 
    35: 
    36: if resource.errors.empty? 
    37:  resource.unlock_access! if unlockable?(resource) 
    38:  flash_message = resource.active_for_authentication? ? :updated : :updated_not_active 
    39:  set_flash_message(:notice, flash_message) if is_flashing_format? 
    40:  sign_in(resource_name, resource) 
    41:  respond_with resource, location: after_resetting_password_path_for(resource) 
    42: else 
    43:  respond_with resource 
    44: end 
    45: end 

我在做什么错?

感谢= d

回答

0

你应该从你的提交按钮删除method: "post"。而是通过html: { method: :post }将HTTP方法设置为表单的一个属性。您的实现在设计passwords/new.html.erb时使用method: :put。下面是从设计默认例如:

<h2>Forgot your password?</h2> 

<%= simple_form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %> 
    <%= f.error_notification %> 

    <div class="form-inputs"> 
    <%= f.input :email, required: true, autofocus: true %> 
    </div> 

    <div class="form-actions"> 
    <%= f.button :submit, "Send me reset password instructions" %> 
    </div> 
<% end %> 

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

由于是创建方法,其发送给USET说明重置密码: 'DEF创建 binding.pry self.resource = resource_class.send_reset_password_instructions(resource_params) 产量资源如果block_given? 如果successfully_sent(资源) respond_with({},位置:after_sending_reset_password_instructions_path_for(RESOURCE_NAME))? 别的 respond_with(资源) 端 end' –

+0

右流是PUT方法?当我输入忘记密码页面时,我在现场输入我的电子邮件并提交?谢谢 –

+0

我下载了https://github.com/RailsApps/rails-devise,并进行了调试。正确的流程是致电#create –