# Save url parameter in a session

**URL:** <https://www.ruby-forum.com/t/save-url-parameter-in-a-session/154000>\
**Category:** Rails\
**Created:** [November 24, 2008, 2:14pm UTC](https://www.ruby-forum.com/t/save-url-parameter-in-a-session/154000 "2008-11-24T14:14:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![PsionBlue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/d07c76/32.png) [@PsionBlue](https://www.ruby-forum.com/u/PsionBlue)\
**Post date:** [November 24, 2008, 2:14pm UTC](https://www.ruby-forum.com/t/save-url-parameter-in-a-session/154000/1 "2008-11-24T14:14:39Z")

</div>

Hi, I am a newb.

Lets say I have url [ABC Home Page - ABC.com](http://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!

---

<div class="post-metadata">

**Author:** ![PsionBlue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/d07c76/32.png) [@PsionBlue](https://www.ruby-forum.com/u/PsionBlue)\
**Post date:** [November 24, 2008, 4:35pm UTC](https://www.ruby-forum.com/t/save-url-parameter-in-a-session/154000/2 "2008-11-24T16:35:39Z")

</div>

On 24 Nov 2008, at 13:13, PsionBlue wrote:

> Hi, I am a newb.
> 
> Lets say I have url [ABC Home Page - ABC.com](http://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

---

<div class="post-metadata">

**Author:** ![PsionBlue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/d07c76/32.png) [@PsionBlue](https://www.ruby-forum.com/u/PsionBlue)\
**Post date:** [November 24, 2008, 7:05pm UTC](https://www.ruby-forum.com/t/save-url-parameter-in-a-session/154000/3 "2008-11-24T19:05:11Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![PsionBlue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/d07c76/32.png) [@PsionBlue](https://www.ruby-forum.com/u/PsionBlue)\
**Post date:** [November 24, 2008, 7:26pm UTC](https://www.ruby-forum.com/t/save-url-parameter-in-a-session/154000/4 "2008-11-24T19:26:54Z")

</div>

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
