Ruby on Rails - Devise Users/Sign_Out Not Working

Ruby on Rails - devise users/sign_out not working

The reason for the error is that the route is inaccessible using the GET HTTP method. Notice what the relevant line looks like in your rake routes output:

destroy_user_session DELETE /users/sign_out(.:format)

Meaning that, if you want to log the user out, you need to send a DELETE request to that url. In rails, you can generate a link that does that like so:

link_to 'Sign out', destroy_user_session_path, :method => :delete

# alternatively (although NOT recommended):

link_to 'Sign out', '/users/sign_out', :method => :delete

The important part is :method => :delete. Note that a DELETE request is not really supported by browsers, rails is actually POSTing the data, but it sends a special parameter that simulates the DELETE method.

The reason behind this is that the "sign out" url is one that would log the current user out, a destructive action. If it was freely accessible through the browser, it could cause various problems. GET requests should never change the state of the server. For more information on this, here's a nice wikipedia article: http://en.wikipedia.org/wiki/REST#RESTful_web_services

Rails Devise Signout not working

I resolved this be modifying ./config/initializers/devise.rb and changing

config.sign_out_via = :get

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).

Cant get devise sign_out to work properly

Alright so after some more digging around, I discovered the following helper method

sign_out_and_redirect(current_user)

using this causes my after_sign_out_path_for function to be triggered and now I have it working.

Rails Devise Gem Sign_Out Fails to sign out

undefined method `sign_out_via_get_because_of=' for Devise:Module

(NoMethodError)

There is no sign_out_via_get_because_of helper for devise. There is only sign_out_via

uninitialized constant UsersController

You don't have users_controller.rb under app/controllers, so is the error.

#app/controllers/users_controller.rb

class UsersController < ApplicationController
end

For "sign_out_via" what exactly should I type?

It depends on the method parameter in your link_to. If it is :method => :delete then config.sign_out_via = :delete else config.sign_out_via = :get.

By convention should I run Rails g controller User or Rails g
controller Users?

You should run rails g controller Users



Related Topics



Leave a reply



Submit