Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## SeasonCollection
- class SeasonCollection < ActiveRecord::Base
- belongs_to :season
- belongs_to :collection
- validates_uniqueness_of :collection_id, :scope => [:season_id]
- end
- ## Season
- class Season < ActiveRecord::Base
- has_many :season_collections
- has_many :collections, :through => :season_collections, :dependent => :destroy
- def self.find_season(query)
- find_by_title(query)
- end
- validates_presence_of :title, :description, :image
- validates_format_of :image,
- :with => %r{\.(gif|jpg|png)$}i,
- :message => 'must be a URL for GIF, JPG, or PNG image.'
- end
- ## Collection
- class Collection < ActiveRecord::Base
- has_many :products
- has_many :season_collections
- has_many :seasons, :through => :season_collections, :dependent => :destroy
- def self.find_cards
- find(:all)
- end
- validates_presence_of :title, :description, :image
- validates_numericality_of :price
- validate :price_must_be_at_least_a_penny
- validates_format_of :image,
- :with => %r{\.(gif|jpg|png)$}i,
- :message => 'must be a URL for GIF, JPG, or PNG image.'
- protected
- def price_must_be_at_least_a_penny
- errors.add(:price, 'should be at least 0.01') if price.nil? || price < 0.01
- end
- end
Add Comment
Please, Sign In to add comment