public
Description: Rails Plugin: macros for adding attribute-specific scopes and orderings to ActiveRecord models
Homepage:
Clone URL: git://github.com/duncanbeevers/named_scope_for.git
named_scope_for / init.rb
100644 14 lines (10 sloc) 0.382 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
class ActiveRecord::Base
 
  def self.named_scope_for attribute
    named_scope "for_#{attribute}",
      lambda { |attribute_value| { :conditions => { attribute => attribute_value } } }
  end
 
  named_scope :order_by, Proc.new { |*attributes|
    raise ArgumentError, 'You must specify an attribute to order by' if attributes.blank?
    { :order => attributes.join(', ') }
  }
 
end