{"id":2769,"date":"2010-02-17T01:07:32","date_gmt":"2010-02-17T05:07:32","guid":{"rendered":"http:\/\/blogs.n1zyy.com\/n1zyy\/?p=2769"},"modified":"2010-02-17T01:07:32","modified_gmt":"2010-02-17T05:07:32","slug":"changing-a-cookies-domain-in-rails","status":"publish","type":"post","link":"https:\/\/blogs.n1zyy.com\/n1zyy\/2010\/02\/17\/changing-a-cookies-domain-in-rails\/","title":{"rendered":"Changing a Cookie&#8217;s Domain in Rails"},"content":{"rendered":"<p>This is one of those things that should be really easy, and that a lot of people probably already know&#8230; But in the hopes of saving someone 30 minutes of frustrated searching, here&#8217;s what you should know.<\/p>\n<p>If you want to change your session cookie&#8217;s path globally, there&#8217;s a <a href=\"http:\/\/szeryf.wordpress.com\/2008\/01\/21\/cookie-handling-in-multi-domain-applications-in-ruby-on-rails\/\">documented setting<\/a>. But what if you want to set some one-off cookie to be from something other than your FQDN?<\/p>\n<dl>\n<dt>It&#8217;s actually simple: rather than setting the cookie to a string (with its value), you use a hash:<\/dt>\n<dt><code><\/dt>\n<dt>cookies[:logged_in_username] = {<\/dt>\n<dd>value => \"jdoe123\", :domain => \".example.com\"\n}\n<\/code><\/dd>\n<\/dl>\n<p>It&#8217;s typical to just do cookies[:logged_in_username] = &#8220;jdoe123&#8221;, but it does accept a hash. (:expires is available, too.)<\/p>\n<p>It turns out this is <a href=\"http:\/\/api.rubyonrails.org\/classes\/ActionController\/Cookies.html\">documented<\/a> exactly where it should be, but that page doesn&#8217;t seem to get much love from Google.<\/p>","protected":false},"excerpt":{"rendered":"<p>This is one of those things that should be really easy, and that a lot of people probably already know&#8230; But in the hopes of saving someone 30 minutes of frustrated searching, here&#8217;s what you should know. If you want &hellip; <a href=\"https:\/\/blogs.n1zyy.com\/n1zyy\/2010\/02\/17\/changing-a-cookies-domain-in-rails\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2769","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/posts\/2769","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/comments?post=2769"}],"version-history":[{"count":0,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/posts\/2769\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/media?parent=2769"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/categories?post=2769"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/tags?post=2769"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}