This project is archived and is in readonly mode.

#2930 ✓resolved
andyjeffries

Fix for not being able to read a cookie set mid-request

Reported by andyjeffries | July 21st, 2009 @ 08:25 AM | in 2.x

Koz asked me to post this here:

Doing this within an action won't return the expected result:

cookies[:abc] = "123"
render :text => cookies[:abc]

The reason has nothing to do with strings/symbols as cookie keys but
is due to the fact that ActionController's cookies method gets a fresh
CookieJar every time it's called.

The fix (monkeypatched here in an initializer) is simply:

module ActionController #:nodoc:
module Cookies

def cookies
  @cookies ||= CookieJar.new(self)
end

end end

The current code in actionpack/lib/action_controller/cookies.rb looks like this:

def cookies
  CookieJar.new(self)
end

I even note that the []= method seems to call super as if this functionality is expected to work.

I know everyone's probably focussed on 3.0, but this is a real doozy of an issue if you hit it (for example, see the blog post at - http://www.40withegg.com/articles/rails-cookies-mangles-the-hash-in... - not mine!).

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages