module ActiveModel::Conversion
def to_key
person = Person.new(1)
end
end
@id = id
def initialize(id)
attr_accessor :id
include ActiveModel::Conversion
class Person
the object is persisted. Returns +nil+ if there are no key attributes.
Returns an Array of all key attributes if any of the attributes is set, whether or not
def to_key key = respond_to?(:id) && id key ? Array(key) : nil end
def to_model
define :to_model yourself returning a proxy object that wraps
If your model does not act like an \Active \Model object, then you should
person.to_model == person # => true
person = Person.new
end
include ActiveModel::Conversion
class Person
returns +self+.
you can use the default :to_model implementation, which simply
If your object is already designed to implement all of the \Active \Model
def to_model self end
def to_param
person = Person.new(1)
end
end
true
def persisted?
end
@id = id
def initialize(id)
attr_accessor :id
include ActiveModel::Conversion
class Person
or +nil+ if persisted? is +false+.
Returns a +string+ representing the object's key suitable for use in URLs,
def to_param (persisted? && (key = to_key) && key.all?) ? key.join(self.class.param_delimiter) : nil end
def to_partial_path
person = Person.new
end
include ActiveModel::Conversion
class Person
ActionPack uses this to find a suitable partial to represent the object.
Returns a +string+ identifying the path associated with the object.
def to_partial_path self.class._to_partial_path end