From 6e00099a28f3271befff03b5ebbb8e6e561cdcd0 Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Wed, 4 Jul 2012 23:11:47 -0500 Subject: update ActiveModel::Conversion documentation [ci skip] --- activemodel/lib/active_model/conversion.rb | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'activemodel') 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 persisted? is false. + # Returns a +string+ representing the object's key suitable for use in URLs, + # or +nil+ if persisted? 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 -- cgit v1.2.3