Postpostmodern » named_scope http://postpostmodern.com Speaking of web development. Wed, 11 Jan 2012 00:21:50 +0000 http://wordpress.org/?v=2.9.1 en hourly 1 Rails Tip: Default Scope http://postpostmodern.com/2008/11/04/rails-tip-default-scope/ http://postpostmodern.com/2008/11/04/rails-tip-default-scope/#comments Tue, 04 Nov 2008 16:27:30 +0000 Jason Johnson http://postpostmodern.com/?p=221 I’ve started using the all method instead of find(:all) for fetching records – mainly because it’s shorter to type, but it’s also easy to override with a named scope. Just create a named_scope called all to set whatever default conditions and order you want. You can always use find(:all) if you want the non-scoped records.

named_scope :all, { 
  :order => 'last_name',
  :conditions => 'activated_at IS NOT NULL'
}

Thoughts, corrections and objections welcome in the comments.

]]>
http://postpostmodern.com/2008/11/04/rails-tip-default-scope/feed/ 1