Here I\'m using Devise Gem for authentication. If someone want to open page without login then it redirect to sign_in page and after signed in it back to the page which user
I has the same doubt and found this, try it too
def after_sign_in_path_for(resource_or_scope) session.fetch 'user_return_to', admin_root_path end