Rails + devise: Trying to delete user account

て烟熏妆下的殇ゞ 提交于 2020-01-03 07:38:52

问题


When I try and delete my account in my rails app I get

No route matches "/users"

My View:

<p>We hate to see you go. <%= link_to "Cancel my account", registration_path(resource_name), :confirm => "Are you sure?", :method => :delete %>.</p>

My routes:

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"}

Am I missing something?


回答1:


According to your rake routes output, you need to use user_registration_path helper instead of just registration_path:

<p>
  We hate to see you go. 
  <%= link_to "Cancel my account", user_registration_path(resource_name), :confirm => "Are you sure?", :method => :delete %>.
</p>

And please double check if the link is triggered with the DELETE method (if the proper js files are included)




回答2:


<p>
  Unhappy?
  <%= link_to "Cancel my account",
      registration_path(current_user),
      data: { confirm: "Are you sure?" },
      method: :delete %>
</p>



回答3:


if you are using devise just do

<%= link_to "My Account", edit_user_registration_path %>


来源:https://stackoverflow.com/questions/8813791/rails-devise-trying-to-delete-user-account

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!