开发者

How to route and delete devise registration?

开发者 https://www.devze.com 2023-04-04 23:57 出处:网络
I\'ve employed devise as the user-authentication gem for my rails web-app. Using this pre-generated line:

I've employed devise as the user-authentication gem for my rails web-app.

Using this pre-generated line:

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

I wish to delete a user's profile.

The weird thing is that when ever I try delete a user's registration, it fails to do so as it can't seem to find the correct route.

I'm getting this:

ActionController::RoutingError (No route matches "/users"):

My routes.rb has:

devise_for :users

My rake routes produces:

      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 G开发者_StackOverflow社区ET    /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"}

What am I missing here?


consider the fact that in routes you have:

 DELETE /users(.:format) {:action=>"destroy", :controller=>"devise/registrations"}

So GET request would not be considered as proper route. Try something like:

<% form_for @user, :html => { :method => 'delete' } do |f| %>
    <%= submit_tag "destroy him" %>
<% end %>


in routes.rb - do this

devise_scope :user do
    get "delete_user", :to => "devise/registrations#destroy", :as => :edit_user_registration
end


Include this line in routes.rb:

devise_scope :user 
    delete "sign out" => "devise/session#destroy"
0

精彩评论

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