-
Notifications
You must be signed in to change notification settings - Fork 5.5k
How To: Redirect to a specific page on successful sign in out
jaylevitt edited this page Feb 23, 2012
·
17 revisions
Devise will by default redirect to the root_path. However, if you defined a user_root_path
for your user model (admin_root_path
for an admin model and so on), Devise will use it instead:
match '/welcome' => "welcome#index", :as => :user_root
If you want more fine grained control, you can simply override after_sign_in_path_for
:
def after_sign_in_path_for(resource)
stored_location_for(resource) || welcome_path
end
To make the above work, the root path obviously needs to be publicly visible!
If what you really want is to change the way /
redirects for logged-in vs. unauthenticated users, you can use the authenticated
route helper:
authenticated :user do
root :to => 'welcome#index'
end
root :to => 'landing#index'
This works a lot like the above, except you use the method:
def after_sign_out_path_for(resource_or_scope)
# logic here
end