Redirect to previous URL after login with Devise
Dumping users at a particular page once they've logged in, no matter what page they were attempting to visit, is a usability nightmare. Finding out how to implementing something you'd think Devise would cover is equally nightmarish.
You can send users back to the page they actually wanted to see quite easily when you're using Devise:
def after_sign_in_path_for(resource_or_scope)
session.fetch 'user_return_to', user_path
end
You can make it a bit more magic when you're working with multiple scopes. A session key will exist for each one, eg. admin_return_to
, other_scope_return_to
, etc.
Written by Lee Machin
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#