diff options
Diffstat (limited to 'activemodel/lib')
-rw-r--r-- | activemodel/lib/active_model/conversion.rb | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/activemodel/lib/active_model/conversion.rb b/activemodel/lib/active_model/conversion.rb index 89d87a8b6f..57b1bc2ada 100644 --- a/activemodel/lib/active_model/conversion.rb +++ b/activemodel/lib/active_model/conversion.rb @@ -45,18 +45,30 @@ module ActiveModel # 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+. + # + # class Person < ActiveRecord::Base + # end + # + # person = Person.create + # person.to_key # => [1] 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 <tt>persisted?</tt> is false. + # Returns a +string+ representing the object's key suitable for use in URLs, + # or +nil+ if <tt>persisted?</tt> is +false+. + # + # class Person < ActiveRecord::Base + # end + # + # person = Person.create + # person.to_param # => "1" def to_param persisted? ? to_key.join('-') : nil end - # Returns a string identifying the path associated with the object. + # Returns a +string+ identifying the path associated with the object. # ActionPack uses this to find a suitable partial to represent the object. # # class Person |