Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[ci skip] correct docs for conversion

  • Loading branch information...
commit bb075e3839d9eea2be5cb0cbed50dafa2c14bb37 1 parent e006327
@aditya-kapoor aditya-kapoor authored
Showing with 12 additions and 5 deletions.
  1. +12 −5 activemodel/lib/active_model/conversion.rb
View
17 activemodel/lib/active_model/conversion.rb
@@ -40,13 +40,15 @@ def to_model
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 @@ def to_key
# 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
Please sign in to comment.
Something went wrong with that request. Please try again.