After a successful DEVISE login, how to redirect user back to previous action that required login?

Viewed 11155

I have an ajax voting button: If a user clicks on a "thumbs up" image, but is not logged in, then they should see a dialog box that asks them to login first.

To do this dialog box,I'm using jQuery and facebox bound to ajax:failure event. Devise will raise a 401 Unauthorized if the user is not logged in. facebox loads the remote html for the login in a pop-up dialog box that presents the DEVISE signin form.

Everything works except after successful login, user is redirected to the homepage. It would be more intuitive if user was redirected back to the post they were looking at so they can continue their vote.

Is there a best practices way of achieving this behavior?

Thanks.

3 Answers
Related