开发者

Rails: Set cookie only on www subdomain?

I have set up an asset host at assets.domain.com but it appears that cookies are being sent with requests to assets.domain.com. I read somewhere that if you have cookies set to domain.com then this will happen.

So I gues开发者_StackOverflow中文版s I'm trying to set cookies only to www.domain.com so that requests to assets.domain.com will not send cookies. (I also have a permanent redirect from domain.com to www.domain.com)

How do I do this in Rails??


To set a cookie on specific domain:

cookies[:my_cookie] = {:value => 'Tasty Cookie', :domain => 'www.domain.com'}

One gotcha is that you must also specify the domain when you delete domain-specific cookies:

cookies.delete(:my_cookie, :domain => 'www.domain.com')

To make sure I don't forget, I usually make a helper for setting and deleting cookies where the default domain is always specified.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜