Flowdock
method

default_scope

Importance_3
Ruby on Rails latest stable (v2.3.8) - 2 notes - Class: ActiveRecord::Base
default_scope(options = {}) protected

Sets the default options for the model. The format of the options argument is the same as in find.

  class Person < ActiveRecord::Base
    default_scope :order => 'last_name, first_name'
  end
Show source
Register or log in to add new notes.
February 26, 2010
3 thanks

default_scope on create

If you specify :conditions in your default_scope in form of a Hash, they will also be applied as default values for newly created objects. Example:

  class Article
    default_scope :conditions => {:published => true}
  end

  Article.new.published? # => true

However:

  class Article
    default_scope :conditions => 'published = 1'
  end

  Article.new.published? # => false