8
Rails redirect user to the previous page after signup or login
source link: https://dev.to/juxsalley/rails-redirect-user-to-the-previous-page-after-signup-or-login-1483
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Rails redirect user to the previous page after signup or login
Aug 11
・1 min read
Let's hit the ball, After working on a subscription platform for a while I realized new user's who wanted to pay for service's on the go have to sign up but after signup, Devise redirect the user to the root page, user's will have to look up what they wanted all over again.
devise allows us to override most of the implementation,
we can create a registration controller.
class Users::RegistrationsController < Devise::RegistrationsController
protected
def after_sign_up_path_for(resource)
url = session[:fall_back_url]
session[:fall_back_url] = nil
if current_user && url
url
end
end
end
Enter fullscreen modeExit fullscreen mode
And inside controller methods we might what to save user's url, we'll save it an session fall_back_url
def show
if !current_user
session[:fall_back_url] = request.url
end
end
Enter fullscreen modeExit fullscreen mode
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK