aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source/upgrading_ruby_on_rails.md
diff options
context:
space:
mode:
authorGodfrey Chan <godfreykfc@gmail.com>2014-03-19 15:19:44 -0700
committerGodfrey Chan <godfreykfc@gmail.com>2014-03-19 15:39:22 -0700
commit3dad856a1a116b8c87c178c32d7dfec3b1241860 (patch)
tree12e58c105b7247941bd9a82610e818d964ce388e /guides/source/upgrading_ruby_on_rails.md
parentc7a307ccd1a9bb10f0e05e055033a44d90cee0e3 (diff)
downloadrails-3dad856a1a116b8c87c178c32d7dfec3b1241860.tar.gz
rails-3dad856a1a116b8c87c178c32d7dfec3b1241860.tar.bz2
rails-3dad856a1a116b8c87c178c32d7dfec3b1241860.zip
Added a warning about serializing data with JSON cookie jars [skip ci]
Closes #14409
Diffstat (limited to 'guides/source/upgrading_ruby_on_rails.md')
-rw-r--r--guides/source/upgrading_ruby_on_rails.md24
1 files changed, 24 insertions, 0 deletions
diff --git a/guides/source/upgrading_ruby_on_rails.md b/guides/source/upgrading_ruby_on_rails.md
index 7467648d49..d58024df3d 100644
--- a/guides/source/upgrading_ruby_on_rails.md
+++ b/guides/source/upgrading_ruby_on_rails.md
@@ -111,6 +111,30 @@ in your application, you can add an initializer file with the following content:
This would transparently migrate your existing `Marshal`-serialized cookies into the
new `JSON`-based format.
+When using the `:json` or `:hybrid` serializer, you should beware that not all
+Ruby objects can be serialized as JSON. For example, `Date` and `Time` objects
+will be serialized as strings, and `Hash`es will have their keys stringified.
+
+```ruby
+class CookiesController < ApplicationController
+ def set_cookie
+ cookies.encrypted[:expiration_date] = Date.tomorrow # => Thu, 20 Mar 2014
+ redirect_to action: 'read_cookie'
+ end
+
+ def read_cookie
+ cookies.encrypted[:expiration_date] # => "2014-03-20"
+ end
+end
+```
+
+It's advisable that you only store simple data (strings and numbers) in cookies.
+If you have to store complex objects, you would need to handle the conversion
+manually when reading the values on subsequent requests.
+
+If you use the cookie session store, this would apply to the `session` and
+`flash` hash as well.
+
### Flash structure changes
Flash message keys are