new

new(message) Class Public methods

extend_message

extend_message(message) Instance Public methods can be over written to add additional error information.

no_touching

no_touching(&block) Instance Public methods Lets you selectively disable calls to `touch` for the duration of a block. Examples ActiveRecord::Base.no_touching do Project.first.touch # does nothing Message.first.touch # does nothing end Project.no_touching do Project.first.touch # does nothing Message.first.touch # works, but does not touch the associated project end

no_touching?

no_touching?() Instance Public methods

touch

touch(*) Instance Public methods

create

create(attributes = nil, &block) Instance Public methods Creates an object (or multiple objects) and saves it to the database, if validations pass. The resulting object is returned whether the object was saved successfully to the database or not. The attributes parameter can be either a Hash or an Array of Hashes. These Hashes describe the attributes on the objects that are to be created. Examples # Create a single new object User.create(first_name: 'Jamie') # Create an Array

instantiate

instantiate(attributes, column_types = {}) Instance Public methods Given an attributes hash, instantiate returns a new instance of the appropriate class. Accepts only keys as strings. For example, Post.all may return Comments, Messages, and Emails by storing the record's subclass in a type attribute. By calling instantiate instead of new, finder methods ensure they get new instances of the appropriate class for each record. See +ActiveRecord::Inheritance#discriminate_class_for_reco

becomes

becomes(klass) Instance Public methods Returns an instance of the specified klass with the attributes of the current record. This is mostly useful in relation to single-table inheritance structures where you want a subclass to appear as the superclass. This can be used along with record identification in Action Pack to allow, say, Client < Company to do something like render partial: @client.becomes(Company) to render that instance using the companies/company partial instead of

becomes!

becomes!(klass) Instance Public methods Wrapper around becomes that also changes the instance's sti column value. This is especially useful if you want to persist the changed class in your database. Note: The old instance's sti column value will be changed too, as both objects share the same set of attributes.

decrement

decrement(attribute, by = 1) Instance Public methods Initializes attribute to zero if nil and subtracts the value passed as by (default is 1). The decrement is performed directly on the underlying attribute, no setter is invoked. Only makes sense for number-based attributes. Returns self.