开发者

what's the path to destroy registration with devise

I'm trying to add a link so the user can destroy his/her own account. I'm using the built-in registration class.

In my view I have <%= link_to 'Destroy', current_user, :confirm => 'Are you sure you want to destroy your account?', :method => :delete %> pointing to localhost:3000/users/4 by example

First of all, is that the correct link to use? Secondly, how to redirect to root path because presently it looks like it tries to redirect to user with id 4 (and it fails because it is protected).

Rake routes gives DELETE /users(.:format) {:action=>"destroy", 开发者_JS百科:controller=>"devise/registrations"}

Thanks in advance.


Try

<%= link_to 'Destroy', user_registration_path, :confirm => 'Are you sure you want to destroy your account?', :method => :delete %>

It's because of devise treat registration as Singular Resource.

Besides, run rake routes and you can see details about registration routing:

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"}
user_registration      PUT    /users(.:format)                                       {:action=>"update", :controller=>"devise/registrations"}
user_registration      DELETE /users(.:format)                                       {:action=>"destroy", :controller=>"devise/registrations"}

It means:

  • user_registration_path is a helper method that returns /users(.format)
  • Perform DELETE request on /users(.format) will delete the registration
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜