Reputation: 2435
I'm creating a rails app where users log in and look at various pages. Some are private, and others are public. If a user signs out while viewing a private page, he should be redirected to root_path. If a user signs out while viewing a public page, he should be redirected to the same page (which will be rendered slightly differently now that he is signed out).
I want to do this with a conditional statement in the after_sign_out_path_for(resource_or_scope) method within my application_controller. The problem is that the @page variable, which is normally accessed from the pages_controller file, is nil and/or not available in this scope. What is the best way to access this variable (the last loaded page) from a different controller and after the session has been destroyed?
Thanks.
Upvotes: 3
Views: 309
Reputation: 2929
You can keep track of the last page in session variable and add before filter to keep it up to date in the pages controller.
session[:last_page_visited] = @page
You also have access to request.referrer
which will give you the URL of the page where they signed out from. Not sure if you can determine private/public from that, maybe using regex?
Upvotes: 1