Search code examples
ruby-on-railsdevise

Devise/Rails: No route matches [GET] "/users/sign_out"


I'm a bit confused about how devise is routing my requests, for some reason I can't go to the sign-out path in my app now:

ActionController::RoutingError (No route matches [GET] "/users/sign_out")

Here is what my routes related to my User model and Devise look like:

devise_for :users, :controllers => {:registrations => "registrations"}
devise_scope :user do
  get '/settings' => 'registrations#edit'
end

Would defining that scope prevent my other routes from working as well?

Update

I don't think that it's supposed to be GET request, as my link looks like:

<%= link_to "Sign out", destroy_user_session_path, :method => :delete %>

Solution

  • Keep your devise.rb using the correct HTTP method:

    # good 
    config.sign_out_via = :delete
    
    # bad
    config.sign_out_via = :get
    

    Use button_to instead of link_to

    # good 
    = button_to "Sign Out", destroy_user_session_path, method: :delete
    
    # bad
    = link_to "Sign Out", destroy_user_session_path, method: :delete"
    

    If you are using bootstrap (keep it classy)

    = link_to "Sign Out", destroy_user_session_path, method: :delete, class: "btn btn-default btn-sm"