From a3cf68291df3e9f5b23f56a90929c601ffc26ebd Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Fri, 5 Aug 2011 15:28:01 +0530 Subject: ActiveModel::Conversion basic guide --- railties/guides/source/active_model_basics.textile | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'railties/guides') 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 +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. + + +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 + + h3. Changelog * August 5, 2011: Initial version by "Arun Agrawal":http://github.com/arunagw \ No newline at end of file -- cgit v1.2.3