aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2007-06-23 17:52:50 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2007-06-23 17:52:50 +0000
commit1a0cdf74be951f9e732cfb8e6e1cd8a087c8ebdf (patch)
treebd9b1980b774d3a929bd936a09b9fb3851ee4b4e /activerecord/lib
parentb00e6a984df51a2f891c2a4c819ac2ab08359eed (diff)
downloadrails-1a0cdf74be951f9e732cfb8e6e1cd8a087c8ebdf.tar.gz
rails-1a0cdf74be951f9e732cfb8e6e1cd8a087c8ebdf.tar.bz2
rails-1a0cdf74be951f9e732cfb8e6e1cd8a087c8ebdf.zip
Docfix (closes #8096)
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7107 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib')
-rwxr-xr-xactiverecord/lib/active_record/base.rb18
1 files changed, 15 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 527c2fef5a..9d2e186672 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -640,9 +640,21 @@ module ActiveRecord #:nodoc:
end
- # Specifies that the attribute by the name of +attr_name+ should be serialized before saving to the database and unserialized
- # after loading from the database. The serialization is done through YAML. If +class_name+ is specified, the serialized
- # object must be of that class on retrieval, or nil. Otherwise, +SerializationTypeMismatch+ will be raised.
+ # If you have an attribute that needs to be saved to the database as an object, and retrieved as the same object,
+ # then specify the name of that attribute using this method and it will be handled automatically.
+ # The serialization is done through YAML. If +class_name+ is specified, the serialized object must be of that
+ # class on retrieval or +SerializationTypeMismatch+ will be raised.
+ #
+ # ==== Options
+ #
+ # +attr_name+ The field name that should be serialized
+ # +class_name+ Optional, class name that the object should be equal to
+ #
+ # ==== Example
+ # # Serialize a preferences attribute
+ # class User
+ # serialize :preferences
+ # end
def serialize(attr_name, class_name = Object)
serialized_attributes[attr_name.to_s] = class_name
end