I’m giving users the ability to view a preview of a public page, even if they’re not logged in. The public page has a login link, and after a user is redirected to the login page and has logged in, they’re redirected back to the stored public_page.
What I’m looking for is a way to call the clear_location method when a user navigates away from the public_page they’re previewing without logging in. Right now, if a user visits a preview page and then goes back to my homepage and logs in from there, they’re directed back to the preview page they were looking at.
def page_public
store_location
end
def store_location
session[:current_location] = request.fullpath
end
def clear_location
session[:current_location] = nil
end
Sounds as though you just want to call clear_location on visiting any page that isn’t the login page.
Assuming that’s correct, you probably want a before_filter in your ApplicationController, which you would skip for the actions involved in logging in. Perhaps something like this:
Of course, I have no idea what controller handles your login, or exactly which actions are involved, but something along these lines should get the job done.