11

Though there're lots of similar questions, i've searched for it for hours but still can not fix it.

Env rails 3.0.9 ruby 1.9.2 devise 1.4.2

I changed the default login url using:

 5   resources :users
 6   devise_for :users, :path => "", :path_names => { :sign_in => 'login', :sign_out  
     => 'logout', :password => 'secret', :confirmation => 'verification', :unlock =>
     'unblock', :registration => 'register', :sign_up => 'cmon_let_me_in' }

And the http://localhost:3000/login works fine for me But I include

 = link_to 'sign_out', destroy_user_session_path, :method => :delete

in my application.haml, after i click it, it says that no route matchs "/logout" Why? Please help me.

Dogbert
  • 212,659
  • 41
  • 396
  • 397
lhdgriver
  • 315
  • 1
  • 3
  • 17

3 Answers3

11

I had a nearly identical problem and thanks to SO fixed it quite easily (link to my question). First, make sure you have <%= javascript_include_tag :defaults %> in your layout file "application.html.erb."

Then, in your config -> initializers -> "devise.rb" file make sure it says:

config.sign_out_via = :delete

and your "sign_out" code destroy_user_session_path, :method => :delete should work.

Community
  • 1
  • 1
vich
  • 11,836
  • 13
  • 49
  • 66
  • 1
    I m using ruby 1.9.2p180, Rails 3.1.0.rc4 and devise 1.4.2. I've <%= javascript_include_tag "application" %> in my layout file. and using <%= link_to 'Sign out', destroy_user_session_path, :method => :delete %> But still it does not work for me – Sayuj Aug 18 '11 at 07:23
  • In your "devise.rb" initializers file do you have `config.sign_out_via = :delete` or `config.sign_out_via = :get`? There has been a recent update to the way devise handles routes. If you're using the :delete method, you would need to have your sign_out path configured as the first option. – vich Aug 18 '11 at 14:12
  • I am having the same problem. I have it setup correctly in the devise.rb (set to :delete) and the link_to (:method => :delete). I also am using and included JQuery. However, I still receive a 'GET' request. I also have checked the generated code and I see the following for the link_to method: Logout. – Ken Joyner Jan 09 '12 at 02:49
  • I recommend you checkout the answers to my question (http://stackoverflow.com/questions/6557311/no-route-matches-users-sign-out-devise-rails-3). I would recommend going through the various problems different users have been having and you may spot something that will fix yours. If not, let me know. – vich Jan 09 '12 at 14:36
  • 1
    I've just been having a problem with this. It's not something i'd seen before. This answer helped with my debugging though - i noticed that my javascript files weren't loading (in a very early stage of development). I fixed my JS files to load as expected and the routes worked. – Pete Oct 03 '12 at 09:46
5

A little late to this party, but here's some help from another answer

Specify your method:

<%= link_to "sign out", destroy_user_session_path, method: :delete %>
Community
  • 1
  • 1
jahrichie
  • 1,215
  • 3
  • 17
  • 26
4

Set config.sign_out_via = :get in config/initializers/devise.rb to use the following code for your sign out link.

<%= link_to "Sign Out", destroy_user_session_path %>
rxgx
  • 5,089
  • 2
  • 35
  • 43
ashish gupta
  • 49
  • 1
  • 1