# Unique cookie name?

**URL:** <https://www.ruby-forum.com/t/unique-cookie-name/73757>\
**Category:** Rails\
**Created:** [October 26, 2006, 9:41pm UTC](https://www.ruby-forum.com/t/unique-cookie-name/73757 "2006-10-26T21:41:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peter\_Becker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b782af/32.png) [@Peter\_Becker](https://www.ruby-forum.com/u/Peter_Becker)\
**Post date:** [October 26, 2006, 9:41pm UTC](https://www.ruby-forum.com/t/unique-cookie-name/73757/1 "2006-10-26T21:41:07Z")

</div>

Hi,

This is probably easy but I can’t figure it out.  
How can I generate a unique cookie name:  
cookies[:rated] = {:value =\> “yes”, :expires =\> 30.days.from\_now}

The :rated part needs to be the id of the post in my blog, something  
like ‘post\_17’. How can I achieve this?

Thanks,  
Pete

---

<div class="post-metadata">

**Author:** ![Peter\_Becker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b782af/32.png) [@Peter\_Becker](https://www.ruby-forum.com/u/Peter_Becker)\
**Post date:** [October 26, 2006, 10:42pm UTC](https://www.ruby-forum.com/t/unique-cookie-name/73757/2 "2006-10-26T22:42:50Z")

</div>

assuming you have a instance variable @post that contains the curent  
post that was voted on, i would guess:

cookies[“post\_” + @post.id] = {:value =\> “yes”, :expires =\>  
30.days.from\_now}

---

<div class="post-metadata">

**Author:** ![Peter\_Becker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b782af/32.png) [@Peter\_Becker](https://www.ruby-forum.com/u/Peter_Becker)\
**Post date:** [October 26, 2006, 10:44pm UTC](https://www.ruby-forum.com/t/unique-cookie-name/73757/3 "2006-10-26T22:44:50Z")

</div>

err … more precisely

unless cookie[“rated\_post” + @post.id] = “yes”  
#do rating stuff here …  
#then set the cookie  
cookies[“rated\_post\_” + @post.id] = {:value =\> “yes”, :expires =\>  
30.days.from\_now}  
end

though, as this could be easily cheated on, i would suggest to store  
this information in a “ratings” table and check fi the user has an  
entry there for the given post …

---

<div class="post-metadata">

**Author:** ![Peter\_Becker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b782af/32.png) [@Peter\_Becker](https://www.ruby-forum.com/u/Peter_Becker)\
**Post date:** [October 27, 2006, 8:27am UTC](https://www.ruby-forum.com/t/unique-cookie-name/73757/4 "2006-10-27T08:27:09Z")

</div>

Hi

I’ve got an app that worked pretty well with 3 dispatchers, and now that  
I added some (time consuming) webservices on top of it, I would like to  
dedicate a few dispatchers to a specific controller (the webservices  
one).

I came up with this config (using lighttpd. remote is my webservice  
controller)

$HTTP[“url”] =~ “^/remote/” {  
fastcgi.server = ( “.fcgi” =\> (  
“localhost-8003” =\> ( “host” =\> “127.0.0.1”, “port” =\> 8003 ) ,  
“localhost-8004” =\> ( “host” =\> “127.0.0.1”, “port” =\> 8004 ) )  
)  
}

$HTTP[“url”] =~ “^/(?!remote)” {  
fastcgi.server = ( “.fcgi” =\> (  
“localhost-8000” =\> ( “host” =\> “127.0.0.1”, “port” =\> 8000 ) ,  
“localhost-8001” =\> ( “host” =\> “127.0.0.1”, “port” =\> 8001 ) ,  
“localhost-8002” =\> ( “host” =\> “127.0.0.1”, “port” =\> 8002 ) )  
)  
}

And i’m wondering, is this a good choice ? How would you do that instead  
(ie not allow slow web services to block accesses to the web app) ?

Thanks for any hints

Stan

---

<div class="post-metadata">

**Author:** ![Peter\_Becker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b782af/32.png) [@Peter\_Becker](https://www.ruby-forum.com/u/Peter_Becker)\
**Post date:** [October 27, 2006, 7:46am UTC](https://www.ruby-forum.com/t/unique-cookie-name/73757/5 "2006-10-27T07:46:34Z")

</div>

Thorsten L wrote:

> err … more precisely
> 
> unless cookie[“rated\_post” + @post.id] = “yes”  
> #do rating stuff here …  
> #then set the cookie  
> cookies[“rated\_post\_” + @post.id] = {:value =\> “yes”, :expires =\>  
> 30.days.from\_now}  
> end
> 
> though, as this could be easily cheated on, i would suggest to store  
> this information in a “ratings” table and check fi the user has an  
> entry there for the given post …

Thanks! That works great!
