When logout is clicked I want to redirect back to the page the user was on unless that page requires a user to be logged in.
scenario 1 - "back" requires a user 1) User clicks logout from user account page 2) redirected (ultimately) to root_path
scenario 2 - "back" does not require a user 1) User clicks logout from (not user required) events page 2) redirected (ultimately) to events_path
It's been suggested I update my before_filter :require_use method to be something like this:
def require_user
unless current_user
flash[:notice] = "You must be logged in to view this page"
redirect_to user_coming_from_logout_method? root_path : login_path
end
end
Except I've been unable to define #user_coming_from_logout_method?
One might think that it is simply:
request.referrer == "/logout"
But in the above example request.referrer actually == "/user_account", not the intermediate logout method. Very weird, I know.
Suggestions?