new

new(base) Class Public methods Pass in the instance of the object that is using the errors object. class Person def initialize @errors = ActiveModel::Errors.new(self) end end

previous_changes

previous_changes() Instance Public methods Returns a hash of attributes that were changed before the model was saved. person.name # => "bob" person.name = 'robert' person.save person.previous_changes # => {"name" => ["bob", "robert"]}

changes

changes() Instance Public methods Returns a hash of changed attributes indicating their original and new values like attr => [original value, new value]. person.changes # => {} person.name = 'bob' person.changes # => { "name" => ["bill", "bob"] }

changed_attributes

changed_attributes() Instance Public methods Returns a hash of the attributes with unsaved changes indicating their original values like attr => original value. person.name # => "bob" person.name = 'robert' person.changed_attributes # => {"name" => "bob"}

changed?

changed?() Instance Public methods Returns true if any attribute have unsaved changes, false otherwise. person.changed? # => false person.name = 'bob' person.changed? # => true

changed

changed() Instance Public methods Returns an array with the name of the attributes with unsaved changes. person.changed # => [] person.name = 'bob' person.changed # => ["name"]

to_partial_path

to_partial_path() Instance Public methods Returns a string identifying the path associated with the object. ActionPack uses this to find a suitable partial to represent the object. class Person include ActiveModel::Conversion end person = Person.new person.to_partial_path # => "people/person"

to_param

to_param() Instance Public methods 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"

to_model

to_model() Instance Public methods If your object is already designed to implement all of the Active Model you can use the default :to_model implementation, which simply returns self. class Person include ActiveModel::Conversion end person = Person.new person.to_model == person # => true If your model does not act like an Active Model object, then you should define :to_model yourself returning a proxy object that wraps your object with Active Model compliant methods.

to_key

to_key() Instance Public methods Returns an Enumerable 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 end person = Person.create person.to_key # => [1]