Guest User

Untitled

a guest
May 23rd, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. ## SeasonCollection
  2.  
  3. class SeasonCollection < ActiveRecord::Base
  4. belongs_to :season
  5. belongs_to :collection
  6. validates_uniqueness_of :collection_id, :scope => [:season_id]
  7.  
  8. end
  9.  
  10. ## Season
  11.  
  12. class Season < ActiveRecord::Base
  13. has_many :season_collections
  14. has_many :collections, :through => :season_collections, :dependent => :destroy
  15.  
  16. def self.find_season(query)
  17. find_by_title(query)
  18. end
  19.  
  20. validates_presence_of :title, :description, :image
  21. validates_format_of :image,
  22. :with => %r{\.(gif|jpg|png)$}i,
  23. :message => 'must be a URL for GIF, JPG, or PNG image.'
  24. end
  25.  
  26. ## Collection
  27.  
  28. class Collection < ActiveRecord::Base
  29. has_many :products
  30. has_many :season_collections
  31. has_many :seasons, :through => :season_collections, :dependent => :destroy
  32.  
  33. def self.find_cards
  34. find(:all)
  35. end
  36.  
  37. validates_presence_of :title, :description, :image
  38. validates_numericality_of :price
  39. validate :price_must_be_at_least_a_penny
  40. validates_format_of :image,
  41. :with => %r{\.(gif|jpg|png)$}i,
  42. :message => 'must be a URL for GIF, JPG, or PNG image.'
  43.  
  44. protected
  45. def price_must_be_at_least_a_penny
  46. errors.add(:price, 'should be at least 0.01') if price.nil? || price < 0.01
  47. end
  48. end
Add Comment
Please, Sign In to add comment