3
votes

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             
2
Syntactically, it looks right to me. You have devise on Member class only, right?kiddorails
It looks to me like the jQuery UJS isn’t working. That’s what notices the :method => :delete and makes the form submit with that method. Can you see that jQuery and jQuery UJS are actually loading in your browser?Buck Doyle
@kiddorails No , I have devise on User and MemberAhmedShawky
@BuckDoyle I checked and found that jQuery and jQuery UJS are actually loading in browserAhmedShawky
@AhmedShawky Does rake routes gives this route to you?kiddorails

2 Answers

2
votes

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:

  1. 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 
    
  2. 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.

  3. In your routes.rb

    devise_for :members do
      get '/members /sign_out' => 'devise/sessions#destroy'
    end
    
0
votes

In your routes.rb the order should be this

devise_for :members
resources :members

resources :members should come under devise_for :members