Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3 with Devise: No route matches /d/users/sign_out

I am getting the following error when I try to sign out of devise error:

No route matches [GET] "/d/users/sign_out"

My tag is correct, it is as follows:

<%= link_to "Sign Out", destroy_session_path, :method=>:delete %>

My route for devise is:

devise_for :users, :path_prefix=>"d", :controllers=>{:sessions=>"sessions"}

Other routes are:

resources :users#For CRUD defined after devise_for like in Devise Wiki

With a custom controller sessions for ajax login like on the Devise wiki page:

class SessionsController < Devise::SessionsController

 def create
  respond_to do |format|
    format.html{ super }
    format.json do
     resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#failure")
     #resource = warden.authenticate!(:scope => resource_name, :recall => :failure)
     return sign_in_and_redirect(resource_name, resource)
    end
   end
  end

def sign_in_and_redirect(resource_or_scope, resource=nil)
  scope = Devise::Mapping.find_scope!(resource_or_scope)
  resource ||= resource_or_scope
  sign_in(scope, resource) unless warden.user(scope) == resource
  return render :json => {:success => true, :redirect => stored_location_for(scope) || after_sign_in_path_for(resource)}
end

def failure
  return render:json => {:success => false, :errors => ["Login failed."]}
end

end

The devise initializer has:

config.sign_out_via = :delete

Any ideas on what could be causing the problem? I've searched Google and am still stumped.

Update:

Here is a screenshot of the rails routes file for the devise users. Sorry, it is small, but you can right-click then view it by itself for a larger screen.

enter image description here

Update #2:

The jquery_ujs file is included.

Update #3:

It appears in the console that delete is indeed being passed, but it is jumping from the sessions_controller to / then to d/users/sign_out...Not sure how to fix this.

Update #4:

When redirecting it goes first to d/users/sign_out as DELETE, as it should. It then redirects to root_url which then gives the error ERROR Errno::ECONNABORTED: An established connection was aborted by the software in your host machine. It then tries to redirect to d/users/sign_out as GET where it is failing.

like image 475
Travis Pessetto Avatar asked Jul 13 '12 16:07

Travis Pessetto


3 Answers

This appears to be an issue between Devise and Ruby 1.9.2-p290. Updating to Ruby 1.9.3 and running bundle update to ensure the latest version of Devise was used; appears to work.

like image 73
Travis Pessetto Avatar answered Nov 03 '22 11:11

Travis Pessetto


It sounds like you might have removed //= require jquery_ujs from your application.js file. I think that handles the link particulars to make a 'delete' request. Either way, as it is now, you're making a 'GET' which obviously won't hit your destroy_user_session method.

like image 1
Justin Soliz Avatar answered Nov 03 '22 10:11

Justin Soliz


Change:

config.sign_out_via = :delete

to:

config.sign_out_via = :get

See this related:

No route matches "/users/sign_out" devise rails 3

like image 1
Kevin Bedell Avatar answered Nov 03 '22 10:11

Kevin Bedell