How do I have devise / omniauth redirect to the pa

2019-05-13 16:48发布

问题:

I have the authentication through omniauth and that link is available on every page through layout/application.html.haml.

However, when they complete the omniauth authentication, they all go to root.

How can I set it up so they redirect to the actual page from which they clicked on the authentication link (which takes them to the oauth provider).

Thanks

回答1:

You can use request.env['omniauth.origin'].

See https://github.com/intridea/omniauth/wiki/Saving-User-Location



回答2:

I see two options here:

1) Set a session variable on every page you could possibly sign in through like that:

session[:return_to] = request.fullpath

and redirect back to it after signing in:

redirect_to session[:return_to]

or

2) try

redirect_to :back

This depends on how you link your controller actions (haven't worked with omniauth, so I have no experience in that respect)