This project is archived and is in readonly mode.
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
-
andyjeffries July 21st, 2009 @ 08:25 AM
- Tag changed from action_controller, cookies to action_controller, cookies, patch
-
andyjeffries July 21st, 2009 @ 08:30 AM
The original gist (I was trying to be helpful in pasting the whole code here) shows it better as lighthouse appears to have mangled the formatting:
-
Michael Koziarski July 21st, 2009 @ 10:46 PM
- State changed from new to resolved
This was a dupe of #2733 and I've cherry-picked that patch over.
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>