I was having problems redirecting to the last visited page when that page required a sign in Devise Resetting Session On Login and somebody pointed out that you could follow the code example here: https://github.com/plataformatec/devise/wiki/How-To%3A-redirect-to-a-specific-page-on-successful-sign-in
That example calls stored_location_for(resource)…where is that set?
That example works perfectly when used in conjunction with a before_filter :authenticate_user! in my appropriate controllers. Looking at the source code for authenticate_#{resource}!, https://github.com/plataformatec/devise/blob/master/lib/devise/controllers/helpers.rb it doesn’t seem to save the location.
Where in the world is the previous location stored?
The path is stored in
session["user_return_to"](assuminguseris your model name).This appears to be set by
store_location!in failure_app.rbNote that if you only have one devise model, the sign in redirect should work automatically, without you needing to override
after_sign_in_path_forin yourapplication_controller.rb.