Redirect_to kills my session variable


I’m trying to set a session variable in one action of
application_controller.rb, which is then accessed in a second action of
the same controller following a redirect.

Here’s the code.

def cookie_test
if cookies[“cookie_test”].blank?
render :template => “shared/cookies_required”
#redirect back to where the user came from


def cookies_required
return true unless cookies[“cookie_test”].blank?
session[:return_to] = request.request_uri
cookies[“cookie_test”] =
redirect_to :action => “cookie_test” and return false

The method ‘cookies_required’ is called first, which sets the session
variable ‘session[:return_to]’.

I would like to be able to access this variable in the method
‘cookie_test’ following the redirect.

However, when I try to do so, it shows up as nil.

I tried replacing the session variable with a global variable and that
worked fine.
I also tried sending the ‘request.request_uri’ variable as a parameter
to the second action and that worked too.

But why is my session variable dying following the redirect??

Thanks in advance

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs