lhdgriver
lhdgriver

Reputation: 315

rails devise, no route matches logout

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.

Upvotes: 11

Views: 13645

Answers (3)

vich
vich

Reputation: 11896

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.

Upvotes: 11

jahrichie
jahrichie

Reputation: 1235

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 %>

Upvotes: 5

ashish gupta
ashish gupta

Reputation: 49

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 %>

Upvotes: 4

Related Questions