1

My rails version:

rails -v
Rails 4.0.2

I use Devise for users model.

Signout link is:

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

When I click on the link I get this error:

AbstractController::ActionNotFound at /users/sign_out
The action 'show' could not be found for UsersController

By executing rake routes I get this:

destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy

Logs in development.log

Started GET "/users/sign_out" for 127.0.0.1 at 2013-12-28 20:45:06 +0000

AbstractController::ActionNotFound - The action 'show' could not be found for UsersController:
  actionpack (4.0.2) lib/abstract_controller/base.rb:131:in `process'
  actionpack (4.0.2) lib/abstract_controller/rendering.rb:44:in `process'
  actionpack (4.0.2) lib/action_controller/metal.rb:195:in `dispatch'
  actionpack (4.0.2) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
  actionpack (4.0.2) lib/action_controller/metal.rb:231:in `block in action'
  actionpack (4.0.2) lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
  actionpack (4.0.2) lib/action_dispatch/routing/route_set.rb:48:in `call'
  actionpack (4.0.2) lib/action_dispatch/journey/router.rb:71:in `block in call'
  actionpack (4.0.2) lib/action_dispatch/journey/router.rb:59:in `call'
  actionpack (4.0.2) lib/action_dispatch/routing/route_set.rb:680:in `call'

I don't understand why it searches for show action. Just for the fun of it I created the show action in users controller and the show view. What it does then is to redirect to the show action. No clue why.

If you need any other info please let me know. Any clue what's wrong?

3 Answers3

7

If you are using devise model for users and if you are using users resources, then make sure that "devise_for :users" is mentioned prior to "resources :users" in /config/routes.rb

sree durga
  • 71
  • 1
  • 2
3

I fixed it by creating devise_scope like this:

  devise_scope :user do
    get '/users/sign_out' => 'devise/sessions#destroy'
  end

Thanks for the help @David .

1

You say you created a show action in the users_controller. Have you set it up to do the following:

 def show
    @user = current_user 
  end

Note: Your url for logout is becoming something like /users/sign_out and since you have declared users are resources. Rails routes all resourceful routes /user/:id to show action of users controller.

Deej
  • 5,334
  • 12
  • 44
  • 68
  • You are right about the note. However before adding users as resources in routes I had a different error and the delete method was still not working. The error was about using GET to the /sign_out URL. As I mentioned, when I create the show action and click to sign out, it just renders the show view... (btw I did what you mentioned for just testing it) –  Dec 28 '13 at 21:06
  • @Stefanos.Ioannou Can you post your routes.rb – Deej Dec 28 '13 at 21:17