You can use named scopes in rails 2.1 and above
Class Test < ActiveRecord::Base
named_scope :created_after_2005, :conditions => "created_on > 2005-01-01"
named_scope :named_fred, :conditions => { :name => "fred"}
end
then you can do
Test.created_after_2005.named_fred
Or you can give named_scope a lambda allowing you to pass in arguments
Class Test < ActiveRecord::Base
named_scope :created_after, lambda {|date| :conditions => ["created_on > ?", date]}
named_scope :named, lambda{|name| :conditions => { :name => name}}
end
then you can do
Test.created_after(Time.now-1.year).named("fred")