我的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 %>
我puth方法:“post”尝试强制创建方法
我的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="/users/password" class="simple_form new_user" id="new_user" method="post" novalidate="novalidate">
.....
</form>
但是,当我点击提交按钮时,我被发送到控制器中的更新(PUT)方法。我认为,我需要重定向到创建(POST)方法。
Started PUT "/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"=>"duduribeiro.gba@gmail.com"}, "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 :(得分:0)
您应该从提交按钮中删除method: "post"
。而是通过html: { method: :post }
将HTTP方法设置为表单的属性。您的实现在设计密码/ new.html.erb中使用method: :put
。这是Devise的默认示例:
<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" %>