instance method
to_key
Ruby on Rails 4.0.13
Since v3.0.20Signature
to_key()
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]
Source
# File activemodel/lib/active_model/conversion.rb, line 51
def to_key
key = respond_to?(:id) && id
key ? [key] : nil
end
Defined in activemodel/lib/active_model/conversion.rb line 51
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveModel::Conversion