-
Notifications
You must be signed in to change notification settings - Fork 5.5k
How To: Redirect to a specific page on successful # and sign out
Sarah Grefalda edited this page Dec 1, 2023
·
13 revisions
Add this to your ApplicationController
class ApplicationController < ActionController::Base
protected
def after_sign_in_path_for(resource)
# return the path based on resource
end
def after_sign_out_path_for(resource)
# return the path based on resource
end
end
You can override the default behaviour by creating an after_sign_in_path_for
[RDoc] method in your ApplicationController and have it return the path for the page you want:
def after_sign_in_path_for(resource)
current_user_path
end
There exists a similar method for sign out; after_sign_out_path_for
[RDoc]
def after_sign_out_path_for(resource_or_scope)
request.referrer
end
Some versions of Devise may have issues with properly redirecting after signing in (See Issue 4742). Upgrade to the latest version while troubleshooting to help with isolating the issue.