Permalink
Browse files

ActiveModel::Conversion basic guide

  • Loading branch information...
vishnuatrai authored and fxn committed Aug 5, 2011
1 parent d5adaf2 commit a3cf68291df3e9f5b23f56a90929c601ffc26ebd
Showing with 23 additions and 0 deletions.
  1. +23 −0 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

0 comments on commit a3cf682

Please sign in to comment.