From d9238d044a0ad2ef5057c31e574d8cc687bb1b77 Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Fri, 22 Jun 2012 10:44:53 -0500 Subject: update ActiveModel::Conversion documentation [ci skip] --- activemodel/lib/active_model/conversion.rb | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'activemodel/lib/active_model/conversion.rb') diff --git a/activemodel/lib/active_model/conversion.rb b/activemodel/lib/active_model/conversion.rb index d7f30f0920..43d248e5cb 100644 --- a/activemodel/lib/active_model/conversion.rb +++ b/activemodel/lib/active_model/conversion.rb @@ -18,11 +18,10 @@ module ActiveModel # end # # cm = ContactMessage.new - # cm.to_model == self # => true - # cm.to_key # => nil - # cm.to_param # => nil - # cm.to_partial_path # => "contact_messages/contact_message" - # + # cm.to_model == cm # => true + # cm.to_key # => nil + # cm.to_param # => nil + # cm.to_partial_path # => "contact_messages/contact_message" module Conversion extend ActiveSupport::Concern @@ -30,6 +29,13 @@ module ActiveModel # you can use the default :to_model implementation, which simply # returns self. # + # class Person + # include ActiveModel::Conversion + # end + # + # person = Person.new + # person.to_model == person # => true + # # If your model does not act like an Active Model object, then you should # define :to_model yourself returning a proxy object that wraps # your object with Active Model compliant methods. @@ -37,21 +43,28 @@ module ActiveModel self end - # Returns an Enumerable of all key attributes if any is set, regardless - # if the object is persisted or not. + # Returns an Enumerable of all key attributes if any is set, regardless if + # the object is persisted or not. If there no key attributes, returns +nil+. def to_key key = respond_to?(:id) && id key ? [key] : nil end # Returns a string representing the object's key suitable for use in URLs, - # or nil if persisted? is false. + # or +nil+ if persisted? is false. def to_param persisted? ? to_key.join('-') : nil end # Returns a string identifying the path associated with the object. # ActionPack uses this to find a suitable partial to represent the object. + # + # class Person + # include ActiveModel::Conversion + # end + # + # person = Person.new + # person.to_partial_path # => "people/person" def to_partial_path self.class._to_partial_path end -- cgit v1.2.3 From bc818e4bc52efb005051662ab0536790f62b1122 Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Fri, 22 Jun 2012 11:52:57 -0500 Subject: update ActiveModel::Errors documentation and minor fixes [ci skip] --- activemodel/lib/active_model/conversion.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activemodel/lib/active_model/conversion.rb') diff --git a/activemodel/lib/active_model/conversion.rb b/activemodel/lib/active_model/conversion.rb index 43d248e5cb..89d87a8b6f 100644 --- a/activemodel/lib/active_model/conversion.rb +++ b/activemodel/lib/active_model/conversion.rb @@ -27,7 +27,7 @@ module ActiveModel # If your object is already designed to implement all of the Active Model # you can use the default :to_model implementation, which simply - # returns self. + # returns +self+. # # class Person # include ActiveModel::Conversion -- cgit v1.2.3