开发者

Rails: Set cookie only on www subdomain?

开发者 https://www.devze.com 2023-01-16 04:59 出处:网络
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 wi

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

精彩评论

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