redirect_to a path stored in a variable does not complete
From several locations i am checking to see if terms of service has been accepted. If not, the user should be redirected to terms of service and then back to where they were going. I don't want to complicate this question by explaining why i am not using 'request.referer'
What i am doing is using session[:return_to] = a path to return to. So... In one controller i have:
def index
if current_user.tos_at.nil?
开发者_如何学Python session[:return_to] = 'answers path'
redirect_to terms_of_service_controller_index_path
end
...
end
Then after the terms of service are displayed and the user clicks on accept the process is directed to:
def accept_terms_of_service current_user.update_attributes(:tos_at => Time.now) redirect_to session[:return_to] end
Then i am getting:
"You are being redirected."
After that is printed in the browser, nothing happens. If i change the redirect to:
redirect_to answers_path
It redirects to the proper path.
Thanks for your help.
Assign session[:return_to] properly:
session[:return_to] = answers_path
answers_path is a helper, so when you assign session[:return_to] to a value like 'answers_path', its trying to redirect to a page which located in 'answers_path'.
The second way to do this is not to modify session[:return_to] assign, but to replace
redirect_to session[:return_to]
with
redirect_to send(session[:return_to])
精彩评论