respond_to_without_attributes?

respond_to_without_attributes?(method, include_private_methods = false) Instance Public methods A Person instance with a name attribute can ask person.respond_to?(:name), person.respond_to?(:name=), and person.respond_to?(:name?) which will all return true. respond_to?

define_model_callbacks

define_model_callbacks(*callbacks) Instance Public methods #define_model_callbacks accepts the same options define_callbacks does, in case you want to overwrite a default. Besides that, it also accepts an :only option, where you can choose if you want all types (before, around or after) or just some. define_model_callbacks :initializer, only: :after Note, the only: <type> hash will apply to all callbacks defined on that method call. To get around this you can call the #defin

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]

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_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_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"

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"]

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_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"}

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"] }