Skip to content

Instantly share code, notes, and snippets.

@knewter
Forked from rthbound/order.rb
Created December 22, 2011 21:05
Show Gist options
  • Save knewter/1511847 to your computer and use it in GitHub Desktop.
Save knewter/1511847 to your computer and use it in GitHub Desktop.
def self.statuses
Order.all.collect{|x| x.status}.uniq
end
# Currently : STATUSES = ["SHIPPED", "PROCESSING", "RECEIVED", "INCOMPLETE", "VOIDED", "REFUNDED", "FRAUDULENT", "ON HOLD"]
validates_inclusion_of :status, :in => statuses
statuses.map{|x| x.downcase.gsub(" ", "_")}.each { |s| named_scope s, :conditions => { :status => s } }
### JOSH PREFERS
named_scope :with_status, lambda{|s| { :conditions => { :status => s } } }
# > Order.with_status('shipped')
# > Order.with_status(['shipped', 'processing'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment