diff options
author | Aditya Kapoor <aditya.kapoor@vinsol.com> | 2014-06-11 23:29:23 +0530 |
---|---|---|
committer | Aditya Kapoor <aditya.kapoor@vinsol.com> | 2014-06-11 23:29:23 +0530 |
commit | bb075e3839d9eea2be5cb0cbed50dafa2c14bb37 (patch) | |
tree | aebe14338d8f6aa1f245e356a968e9f62780df7a /activemodel/lib/active_model | |
parent | e0063270c2ca576ee6ea77889dab7bfb7110b612 (diff) | |
download | rails-bb075e3839d9eea2be5cb0cbed50dafa2c14bb37.tar.gz rails-bb075e3839d9eea2be5cb0cbed50dafa2c14bb37.tar.bz2 rails-bb075e3839d9eea2be5cb0cbed50dafa2c14bb37.zip |
[ci skip] correct docs for conversion
Diffstat (limited to 'activemodel/lib/active_model')
-rw-r--r-- | activemodel/lib/active_model/conversion.rb | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/activemodel/lib/active_model/conversion.rb b/activemodel/lib/active_model/conversion.rb index 374265f0d8..9c9b6f4a77 100644 --- a/activemodel/lib/active_model/conversion.rb +++ b/activemodel/lib/active_model/conversion.rb @@ -40,13 +40,15 @@ module ActiveModel self end - # Returns an Enumerable of all key attributes if any is set, regardless if + # Returns an Array of all key attributes if any is set, regardless if # the object is persisted or not. Returns +nil+ if there are no key attributes. # - # class Person < ActiveRecord::Base + # class Person + # include ActiveModel::Conversion + # attr_accessor :id # end # - # person = Person.create + # person = Person.create(id: 1) # person.to_key # => [1] def to_key key = respond_to?(:id) && id @@ -56,10 +58,15 @@ module ActiveModel # 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 + # class Person + # include ActiveModel::Conversion + # attr_accessor :id + # def persisted? + # true + # end # end # - # person = Person.create + # person = Person.create(id: 1) # person.to_param # => "1" def to_param (persisted? && key = to_key) ? key.join('-') : nil |