Problem Signing Out with Devise on My App

Problem Signing Out with Devise on my App

Actually, ignore my previous answer and try this:

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

No route matches /users/sign_out devise rails 3

I think the route for signing out is a DELETE method. This means that your sign out link needs to look like this:

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

Yours doesn't include the :method => :delete part. Also, please note that for this to work you must also include <%= javascript_include_tag :defaults %> in your layout file (application.html.erb).

devise - can't display sign in or sign out in rails view

This is probably because you are defining your own current_user method. This will then override the one that is provided by Devise.

If you look the source for the user_signed_in? method, you can see that current user (the one defined by Devise) is used by this method. It is likely that Devise doesn't save the current user to session[:user_id], which is what your method is checking. Consequently, when Devise calls your method from within user_signed_in?, it always returns false.

Try removing the current user method from your ApplicationController and see if that resolves the problem.

Sign Out not working on Heroku - using Devise gem and Rails 4

I found the solution. The problem is that Rails 4 handles assets differently than Rails 3. By default, Rails 4 doesn't serve static assets. You can manually change this in config/application.rb by setting:

config.serve_static_assets = true

Another option (and the one that Heroku recommends) is to use the rails_12factor gem. Adding this to your Gemfile and running bundle install will make the adjustment for you and also set your logger to standard out. It can be used with Rails 3 and Rails 4 both.

gem 'rails_12factor', group: :production

I opted to use the gem. After I ran bundle install, committed the changes, and redeployed - my sign out link worked fine with no need to change the method. My scss files were also compiled and implemented accurately after this. (I hadn't done anything with the styles before, so I didn't realize this was an issue. Funny how encountering a new problem can help lead to a solution...)

Here are the resources that helped me:

https://devcenter.heroku.com/articles/rails-4-asset-pipeline

https://github.com/heroku/rails_12factor

Devise: Why doesn't my logout link work?

The problem lies in the fact that in your logs the signout request is a GET request.

Started GET "/users/sign_out"

But the signout route is a DELETE

destroy_user_session DELETE /users/sign_out(.:format) 

The reason why you are getting the exception is that is it getting confused with one of the routes created by resources :users which would be something like

edit_user GET /users/(:id)(.:format) {:action=>"edit", :controller=>"users"}

Basically 'sign_out' is being mistaken as a id.

I'm not sure why the delete link is not going through as a DELETE request. Though changing

config.sign_out_via = :delete

to be :get might solve the problem.



Related Topics



Leave a reply



Submit