method

default_scope

Importance_2
Ruby on Rails latest stable (v2.3.4) - 2 notes - Class: ActiveRecord::Base
  • v1.0.0
  • v1.1.0
  • v1.1.1
  • v1.1.2
  • v1.1.3
  • v1.1.4
  • v1.1.5
  • v1.1.6
  • v1.2.0
  • v1.2.1
  • v1.2.2
  • v1.2.3
  • v1.2.4
  • v1.2.5
  • v1.2.6
  • v2.0.0
  • v2.0.1
  • v2.0.2
  • v2.0.3
  • v2.1.0
  • v2.2.1
  • 2.3.2 (0)
  • 2.3.4 (0)
  • What's this?
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
0 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