Calling a Rails controller method when a user navigates away from a view
===

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