1
votes

I am using the Devise 1.4.9 authentication gem with my Rails 3.1 app and when I click on any link I get routing errors. Here's what happens when I click on the Sign Out link:

Routing Error

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

I am creating the link with this method:

<%= link_to('Sign Out', destroy_user_session_path, :method => :delete) %>

This is how the link is rendered in the source:

<a href="/users/sign_out" data-method="delete" rel="nofollow">Sign Out</a>

I have this line in my layout header:

<%= javascript_include_tag :defaults %>

These lines are in my application.js file:

//
// = require jquery
// = require jquery_ujs
// = require_tree .

Here is the relevant rake routes output:

          new_user_session GET        /users/sign_in(.:format)                  {:action=>"new", :controller=>"devise/sessions"}
              user_session POST       /users/sign_in(.:format)                  {:action=>"create", :controller=>"devise/sessions"}
      destroy_user_session DELETE     /users/sign_out(.:format)                 {:action=>"destroy", :controller=>"devise/sessions"}
             user_password POST       /users/password(.:format)                 {:action=>"create", :controller=>"devise/passwords"}
         new_user_password GET        /users/password/new(.:format)             {:action=>"new", :controller=>"devise/passwords"}
        edit_user_password GET        /users/password/edit(.:format)            {:action=>"edit", :controller=>"devise/passwords"}
                           PUT        /users/password(.:format)                 {:action=>"update", :controller=>"devise/passwords"}
  cancel_user_registration GET        /users/cancel(.:format)                   {:action=>"cancel", :controller=>"devise/registrations"}
         user_registration POST       /users(.:format)                          {:action=>"create", :controller=>"devise/registrations"}
     new_user_registration GET        /users/sign_up(.:format)                  {:action=>"new", :controller=>"devise/registrations"}
    edit_user_registration GET        /users/edit(.:format)                     {:action=>"edit", :controller=>"devise/registrations"}
                           PUT        /users(.:format)                          {:action=>"update", :controller=>"devise/registrations"}
                           DELETE     /users(.:format)                          {:action=>"destroy", :controller=>"devise/registrations"}

I've tried pretty much everything in this thread to no avail:

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

I've restarted the server numerous times.

This issue seems to have come up in the past, but not a single solution described has changed this behavior and I'm stumped.

3
hey @wrburgess can you check and see if you have gem 'jquery-rails' in your Gemfile. I'm also curious if you can check your source in the browser and check if jquery_ujs is being included. You should see something similar to: <script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script>Michal Kuklis
I do have that gem being loaded, but the scripts are not...might be the issueRandy Burgess

3 Answers

0
votes

Please try to rename :defaults to :application when passing it to javascript_include_tag in case you define your includes in application.js

<%= javascript_include_tag :application %>
0
votes

One, you might want to use a button (can be styled to look like a link) for something destructive, as per this checklist for using GET. That alone may fix it.

Two, you need the csrf_meta_tag in the file, which you probably already have.

Have you confirmed the JS files are actually being loaded?

(I thought the // = with the space might be a problem, but apparently it works as well as //= as Rails creates by default.)

0
votes

Writing

devise_scope :user do 
  get "/users/sign_out", :to => "devise/sessions#destroy" 
  end 

in my routes.rb solved the problem for me.