Created
January 19, 2013 19:30
-
-
Save derwiki/4574572 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Item < ActiveRecord::Base | |
attr_accessible :description, :owner_id, :title, :image_url, :weekly, :daily, | |
:amazon_url, :image, :brand, :component | |
belongs_to :owner, class_name: 'User' | |
COMPONENTS = [:lens, :body, :accessory].each do |component| | |
scope component.to_sym, where(component: component) | |
end | |
BRANDS = [:canon, :nikon, :sony, :olympus, :other].each do |brand| | |
scope brand.to_sym, where(brand: brand) | |
end | |
end | |
1.9.3p327 :005 > Item.canon.body.collect(&:title) | |
Item Load (0.3ms) SELECT "items".* FROM "items" WHERE "items"."brand" = 'canon' AND "items". | |
"component" = 'body' | |
=> ["Canon 60D Body", "Canon Rebel XTi 10.1 MP Body"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment