From 9c8826bcd2238d73e904e9ddc2bc7a779716318b Mon Sep 17 00:00:00 2001 From: Vasily Polovnyov Date: Fri, 25 Jul 2014 23:44:05 +0400 Subject: [PATCH 1/2] [ci skip] Mention the change in nil handling for serialized attributes in "Upgrading from Rails 3.2 to Rails 4.0" --- guides/source/upgrading_ruby_on_rails.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/guides/source/upgrading_ruby_on_rails.md b/guides/source/upgrading_ruby_on_rails.md index b3e4505fc0..2a7b6a10a9 100644 --- a/guides/source/upgrading_ruby_on_rails.md +++ b/guides/source/upgrading_ruby_on_rails.md @@ -592,6 +592,9 @@ Rails 4.0 no longer supports loading plugins from `vendor/plugins`. You must rep * Rails 4.0 has changed `serialized_attributes` and `attr_readonly` to class methods only. You shouldn't use instance methods since it's now deprecated. You should change them to use class methods, e.g. `self.serialized_attributes` to `self.class.serialized_attributes`. +* When using the default coder, assigning `nil` to a serialized attribute will save it +to the database as `NULL` instead of passing the `nil` value through YAML (`"--- \n...\n"`). + * Rails 4.0 has removed `attr_accessible` and `attr_protected` feature in favor of Strong Parameters. You can use the [Protected Attributes gem](https://github.com/rails/protected_attributes) for a smooth upgrade path. * If you are not using Protected Attributes, you can remove any options related to From 4bfd0cef5bc0e6c052f8683ac0510845b7748a72 Mon Sep 17 00:00:00 2001 From: Vasily Polovnyov Date: Sat, 26 Jul 2014 22:34:56 +0400 Subject: [PATCH 2/2] [ci skip] Clarify the "Serialized Attributes" section Mention that the change in nil handling for serialized attributes affects custom coders. --- guides/source/upgrading_ruby_on_rails.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/guides/source/upgrading_ruby_on_rails.md b/guides/source/upgrading_ruby_on_rails.md index 2a7b6a10a9..0b8db49ef8 100644 --- a/guides/source/upgrading_ruby_on_rails.md +++ b/guides/source/upgrading_ruby_on_rails.md @@ -54,7 +54,8 @@ NOTE: This section is a work in progress. ### Serialized attributes -When assigning `nil` to a serialized attribute, it will be saved to the database +When using a custom coder (e.g. `serialize :metadata, JSON`), +assigning `nil` to a serialized attribute will save it to the database as `NULL` instead of passing the `nil` value through the coder (e.g. `"null"` when using the `JSON` coder).