我已经将devise用作我的rails web-app的用户身份验证gem。
使用此预先生成的行:
<p>Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), :confirm => "Are you sure?", :method => :delete %>.</p>
我希望删除用户的个人资料。
奇怪的是,当我尝试删除用户的注册时,它无法执行此操作,因为它似乎无法找到正确的路由。
我得到了这个:
ActionController::RoutingError (No route matches "/users"):
我的routes.rb
有:
devise_for :users
我的rake routes
产生:
new_user_session GET /users/sign_in(.:format) {:action=>"new", :controller=>"devise/sessions"}
user_session POST /users/sign_in(.:format) {:action=>"create", :controller=>"devise/sessions"}
destroy_user_session GET /users/sign_out(.:format) {:action=>"destroy", :controller=>"devise/sessions"}
user_password POST /users/password(.:format) {:action=>"create", :controller=>"devise/passwords"}
new_user_password GET /users/password/new(.:format) {:action=>"new", :controller=>"devise/passwords"}
edit_user_password GET /users/password/edit(.:format) {:action=>"edit", :controller=>"devise/passwords"}
PUT /users/password(.:format) {:action=>"update", :controller=>"devise/passwords"}
user_registration POST /users(.:format) {:action=>"create", :controller=>"devise/registrations"}
new_user_registration GET /users/sign_up(.:format) {:action=>"new", :controller=>"devise/registrations"}
edit_user_registration GET /users/edit(.:format) {:action=>"edit", :controller=>"devise/registrations"}
PUT /users(.:format) {:action=>"update", :controller=>"devise/registrations"}
DELETE /users(.:format) {:action=>"destroy", :controller=>"devise/registrations"}
user_confirmation POST /users/confirmation(.:format) {:action=>"create", :controller=>"devise/confirmations"}
new_user_confirmation GET /users/confirmation/new(.:format) {:action=>"new", :controller=>"devise/confirmations"}
GET /users/confirmation(.:format) {:action=>"show", :controller=>"devise/confirmations"}
我在这里缺少什么?
答案 0 :(得分:0)
考虑你在路线中的事实:
DELETE /users(.:format) {:action=>"destroy", :controller=>"devise/registrations"}
因此GET请求不会被视为正确的路由。尝试类似:
<% form_for @user, :html => { :method => 'delete' } do |f| %>
<%= submit_tag "destroy him" %>
<% end %>
答案 1 :(得分:0)
- 执行此操作
devise_scope :user do
get "delete_user", :to => "devise/registrations#destroy", :as => :edit_user_registration
end