validates_uniqueness_of

validates_uniqueness_of(*attr_names) Instance Public methods Validates whether the value of the specified attributes are unique across the system. Useful for making sure that only one user can be named âdavidhhâ. class Person < ActiveRecord::Base validates_uniqueness_of :user_name end It can also validate whether the value of the specified attributes are unique based on a :scope parameter: class Person < ActiveRecord::Base validates_uniqueness_of :user_name, scope: :acco

validates_presence_of

validates_presence_of(*attr_names) Instance Public methods Validates that the specified attributes are not blank (as defined by Object#blank?), and, if the attribute is an association, that the associated object is not marked for destruction. Happens by default on save. class Person < ActiveRecord::Base has_one :face validates_presence_of :face end The face attribute must be in the object and it cannot be blank or marked for destruction. If you want to validate the presence

validates_associated

validates_associated(*attr_names) Instance Public methods Validates whether the associated object or objects are all valid. Works with any kind of association. class Book < ActiveRecord::Base has_many :pages belongs_to :library validates_associated :pages, :library end WARNING: This validation must not be used on both ends of an association. Doing so will lead to a circular dependency and cause infinite recursion. NOTE: This validation will not fail if the association ha

create!

create!(attributes = nil, &block) Instance Public methods Creates an object just like Base.create but calls save! instead of save so an exception is raised if the record is invalid.

new

new(model) Class Public methods

new

new(record, attribute) Class Public methods

with_transaction_returning_status

with_transaction_returning_status() Instance Public methods Executes method within a transaction and captures its return value as a status flag. If the status is true the transaction is committed, otherwise a ROLLBACK is issued. In any case the status flag is returned. This method is available within the context of an ActiveRecord::Base instance.

transaction

transaction(options = {}, &block) Instance Public methods See ActiveRecord::Transactions::ClassMethods for detailed documentation.

rollback_active_record_state!

rollback_active_record_state!() Instance Public methods Reset id and @new_record if the transaction rolls back.

add_to_transaction

add_to_transaction() Instance Public methods Add the record to the current transaction so that the after_rollback and after_commit callbacks can be called.