Reputation: 6470
When my application_controller.rb
redirects to users_path
like this:
def after_sign_in_path_for(resource)
users_path
end
the redirect works. But if I change it to user_path
:
def after_sign_in_path_for(resource)
user_path
end
I get a routing error. Here is my routes.rb:
devise_for :users
get "users/show"
resources :orders
resources :users do
resources :orders
end
I thought maybe I should pass the userID like this:
def after_sign_in_path_for(resource)
@user = User.find(params[:id])
user_path(@user)
end
but the error comes back Couldn't find User without an ID
. Help?
Upvotes: 2
Views: 2910
Reputation: 8163
I spent several hours trying to get the same functionality, and this is the code in the ApplicationController that ended up working for me:
def after_sign_in_path_for(resource)
current_user
end
If I ever tried current_user_path
, I always got undefined local variable or method current_user_path
errors.
Also, I'm using Rails 3.2.8 and Devise 2.1.2.
Hope that helps.
Upvotes: 1
Reputation: 1396
I think you should try current_user
after login
user_path(current_user)
Upvotes: 7