Skip to content

How To: Redirect to a specific page on successful sign in out

josevalim 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!

After signing out

This works a lot like the above, except you use the method:

def after_sign_out_path_for(resource_or_scope)
  # logic here
end
Clone this wiki locally