Reputation: 910
I use rails 4.1.0 and Devise. I've setup devise on Member
model class and when I click "log out" link as bellow:
<%= link_to "Log out", destroy_member_session_path, :method => :delete %>
I get the following error only on production environment:
No route matches [GET] "/members/sign_out Devise
Note: I've precompiled my assets and include the following in my application.js file:
//= require jquery
//= require jquery_ujs
Upvotes: 3
Views: 287
Reputation: 4436
This happens when you do not have the gem jquery-ujs
installed or you are not calling the resulting javascript in your application via = javascript_include_tag "application"
, the response will be sent as a GET request, and the route will fail.
Check options below to make it work:
In devise.rb
Change config.sign_out_via
= :get
(not
recommended, since DELETE is the appropriate RESTful way to use this)
config.sign_out_via = :delete
Use button instead of link_to
to
= button_to('Logout', destroy_user_session_path, :method => :delete)
With button_to Rails will do the heavy lifting on making the proper DELETE call. You can then style the button to look like a link if you wish.
In your routes.rb
devise_for :members do
get '/members /sign_out' => 'devise/sessions#destroy'
end
Upvotes: 2
Reputation: 17834
In your routes.rb
the order should be this
devise_for :members
resources :members
resources :members
should come under devise_for :members
Upvotes: 0