aboutsummaryrefslogtreecommitdiffstats
path: root/railties/guides/source
diff options
context:
space:
mode:
authorVishnu Atrai <vishnu.atrai@gmail.com>2011-08-05 15:28:01 +0530
committerXavier Noria <fxn@hashref.com>2011-08-13 16:22:32 -0700
commita3cf68291df3e9f5b23f56a90929c601ffc26ebd (patch)
tree2094f07e169b14a1a4b2b5e04e9b6a40d111e8bd /railties/guides/source
parentd5adaf2d38f81429e21d9670b6a852668edb3757 (diff)
downloadrails-a3cf68291df3e9f5b23f56a90929c601ffc26ebd.tar.gz
rails-a3cf68291df3e9f5b23f56a90929c601ffc26ebd.tar.bz2
rails-a3cf68291df3e9f5b23f56a90929c601ffc26ebd.zip
ActiveModel::Conversion basic guide
Diffstat (limited to 'railties/guides/source')
-rw-r--r--railties/guides/source/active_model_basics.textile23
1 files changed, 23 insertions, 0 deletions
diff --git a/railties/guides/source/active_model_basics.textile b/railties/guides/source/active_model_basics.textile
index 92fa5bc8f4..daf41d2296 100644
--- a/railties/guides/source/active_model_basics.textile
+++ b/railties/guides/source/active_model_basics.textile
@@ -67,6 +67,29 @@ class Person
end
</ruby>
+h4. Conversion
+
+If a class defines persisted? and id methods then you can include Conversion module in that class and you can able to call Rails conversion methods to objects of that class.
+
+<ruby>
+class Person
+ include ActiveModel::Conversion
+
+ def persisted?
+ false
+ end
+
+ def id
+ nil
+ end
+end
+
+person = Person.new
+person.to_model == person #=> true
+person.to_key #=> nil
+person.to_param #=> nil
+</ruby>
+
h3. Changelog
* August 5, 2011: Initial version by "Arun Agrawal":http://github.com/arunagw \ No newline at end of file