# How can I create a 2nd/separate cookie for my app? (i.e. an

**URL:** <https://www.ruby-forum.com/t/how-can-i-create-a-2nd-separate-cookie-for-my-app-i-e-an/108484>\
**Category:** Rails\
**Created:** [July 3, 2007, 11:49pm UTC](https://www.ruby-forum.com/t/how-can-i-create-a-2nd-separate-cookie-for-my-app-i-e-an/108484 "2007-07-03T23:49:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [July 3, 2007, 11:49pm UTC](https://www.ruby-forum.com/t/how-can-i-create-a-2nd-separate-cookie-for-my-app-i-e-an/108484/1 "2007-07-03T23:49:45Z")

</div>

Hi,

How can I create a 2nd/separate cookie for my app (i.e. and not use the  
session tracking cookie). Is this possible?

Currently the timezone id I’m saving via “cookies[:tz]” gets stored ok  
in  
the application cookie (along with session\_id etc), however the session  
cookie disappears after the browser is closed - and I don’t want to keep  
this session cookie “alive” longer than this.

Tks

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [July 4, 2007, 12:07am UTC](https://www.ruby-forum.com/t/how-can-i-create-a-2nd-separate-cookie-for-my-app-i-e-an/108484/2 "2007-07-04T00:07:46Z")

</div>

Greg H. wrote:

> Tks

That sound to me like the kind of thing you might want to be storing in  
the users table.

–  
[http://www.5valleys.com/](http://www.5valleys.com/)

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [July 4, 2007, 12:09am UTC](https://www.ruby-forum.com/t/how-can-i-create-a-2nd-separate-cookie-for-my-app-i-e-an/108484/3 "2007-07-04T00:09:47Z")

</div>

I use this in my controller…

cookies[:\_my\_host\_tz]= { :value =\> “PST”, :expires =\>  
30.days.from\_now, :path =\> “/” }

and checking in Firefox, it does create a separate cookie from the  
sessions cookie.  
there is a \_my\_host\_session\_id and a \_my\_host\_tz cookie.

On Jul 3, 2:48 pm, “Greg H.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [July 4, 2007, 1:15am UTC](https://www.ruby-forum.com/t/how-can-i-create-a-2nd-separate-cookie-for-my-app-i-e-an/108484/4 "2007-07-04T01:15:51Z")

</div>

PS. How are you accessing the timezone info in your app out of  
curiosity?

I’ve doing the following. Any comments welcomed?

- I’m not accessing via the cookie as if it’s not set and I set it in a  
before filter it remains unset until the next browser request, so what  
I’m  
doing is:
- Application code accesses value from session, with cookie value being  
used  
when browser closed/opened.
- When even setting timezone in app set both cookie & session.
- BeforeFilter = Ensure that both session and cookie contains value. If  
cookie is nil then set it with with session value and vica versa. If  
both  
are nil then set a default in both cookie and session

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [July 4, 2007, 12:13am UTC](https://www.ruby-forum.com/t/how-can-i-create-a-2nd-separate-cookie-for-my-app-i-e-an/108484/5 "2007-07-04T00:13:48Z")

</div>

oh, perhaps I was misinterpreting the “see cookie info” from the web  
developer firefox plugin (i.e. thought it was the same cookie) - let me  
try  
this wolfmanjm - tks`

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [July 4, 2007, 2:40am UTC](https://www.ruby-forum.com/t/how-can-i-create-a-2nd-separate-cookie-for-my-app-i-e-an/108484/6 "2007-07-04T02:40:55Z")

</div>

Sorry I’m not actually using the cookie to store TZ info, I’m actually  
using it to store last view time, but the technique for cookie storing  
should be the same 🙂

On Jul 3, 4:14 pm, “Greg H.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
