We've moved discussions to Discord

Is there a way to link to sign_in with a specified after_sign_in redirect?

Rob Jonson
I have a public page showing some resources, but the user needs to sign in if they want to comment

I currently have a 'sign in to comment' link which just points to new_user_session_path

What I'd like is a link with something like

link_to, new_user_session_path(then_redirect_back_to: this_path), "Sign in to comment"

is there something like that built in? If not - what would be the cleanest way to go about it?

iqbal Hasnan
instead of pointing to new_user_session_path, point to new_comment_path and make sure it has before_action :authenticate_user! in comment controller. 

the redirection after login has been handled in application_controller: after_sign_in_path_for
Rob Jonson
thanks for the response. I did think about that - but I don't really have a new_coment_path. That's a post method for any 'commentable' resource.

the place that I want them to be redirected to is commentable_resource#show
which itself doesn't require a login

I could create a commentable_resource#show_with_login route if necessary
but I thought there might be a cleaner solution...



Notifications
You’re not receiving notifications from this thread.