Forum: Ruby on Rails save url parameter in a session

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
09b6ab65b8addd331a07433b5cf72667?d=identicon&s=25 PsionBlue (Guest)
on 2008-11-24 14:14
(Received via mailing list)
Hi, I am a newb.

Lets say I have url abc.com/?animal=cat. What I need to do is save the
param in the session file but still have it available to other
controllers. I can get it to work within one controller with:

session[:animal] = param[:animal]

but I cannot get it to save and be used by other controllers. I can
hack it by adding:

session[:animal] = "cat"

in the application.rb and adding a before filter to the controller.
How do I add a param from a url in a session to be used by all
controllers?

Thanks!
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-11-24 16:35
(Received via mailing list)
On 24 Nov 2008, at 13:13, PsionBlue wrote:

>
> Hi, I am a newb.
>
> Lets say I have url abc.com/?animal=cat. What I need to do is save the
> param in the session file but still have it available to other
> controllers. I can get it to work within one controller with:
>
> session[:animal] = param[:animal]
>
There's no reason that shouldn't work. If there's something you're
doing wrong you haven't shown us that bit yet.

Fred
09b6ab65b8addd331a07433b5cf72667?d=identicon&s=25 PsionBlue (Guest)
on 2008-11-24 19:05
(Received via mailing list)
So sessions are not cleared out controller to controller? I found
another way (prob. a better way), I am using the redirect_to to pass
the variable. The funny thing about problems is that you need to know
what the question is before you can solve it I guess... Thanks!
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-11-24 19:26
(Received via mailing list)
On 24 Nov 2008, at 18:04, PsionBlue wrote:

>
> So sessions are not cleared out controller to controller?

Nope. would rather defeat the point of the session
>

> I found
> another way (prob. a better way), I am using the redirect_to to pass
> the variable. The funny thing about problems is that you need to know
> what the question is before you can solve it I guess... Thanks!

That sounds like a sane way to do it.

Fred
This topic is locked and can not be replied to.