This project is archived and is in readonly mode.

#2930 ✓resolved

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 ||=

end end

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

def cookies

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 - - 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=""></a>