new

new() Class Public methods

seconds_since_midnight

seconds_since_midnight() Instance Public methods Seconds since midnight: DateTime.now.seconds_since_midnight.

validates_with

validates_with(*args, &block) Instance Public methods Passes the record off to the class or classes specified and allows them to add errors based on more complex conditions. class Person include ActiveModel::Validations validate :instance_validations def instance_validations validates_with MyValidator end end Please consult the class method documentation for more information on creating your own validator. You may also pass it multiple classes, like so: class Per

beginning_of_hour

beginning_of_hour() Instance Public methods Returns a new DateTime representing the start of the hour (hh:00:00). at_beginning_of_hour

next_month

next_month() Instance Public methods Short-hand for #months_since(1).

validates_presence_of

validates_presence_of(*attr_names) Instance Public methods Validates that the specified attributes are not blank (as defined by Object#blank?). Happens by default on save. class Person < ActiveRecord::Base validates_presence_of :first_name end The first_name attribute must be in the object and it cannot be blank. If you want to validate the presence of a boolean field (where the real values are true and false), you will want to use validates_inclusion_of :field_name, in: [tru

pluck

pluck(*column_names) Instance Public methods Use pluck as a shortcut to select one or more attributes without loading a bunch of records just to grab the attributes you want. Person.pluck(:name) instead of Person.all.map(&:name) Pluck returns an Array of attribute values type-casted to match the plucked column names, if they can be deduced. Plucking an SQL fragment returns String values by default. Person.pluck(:id) # SELECT people.id FROM people # => [1, 2, 3] Person.plu

unscope

unscope(*args) Instance Public methods Removes an unwanted relation that is already defined on a chain of relations. This is useful when passing around chains of relations and would like to modify the relations without reconstructing the entire chain. User.order('email DESC').unscope(:order) == User.all The method arguments are symbols which correspond to the names of the methods which should be unscoped. The valid arguments are given in VALID_UNSCOPING_VALUES. The method can also

beginning_of_quarter

beginning_of_quarter() Instance Public methods Returns a new date/time at the start of the quarter. Example: 1st January, 1st July, 1st October. DateTime objects will have a time set to 0:00. at_beginning_of_quarter

increment

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