Created
September 28, 2011 16:31
-
-
Save eileencodes/1248405 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 Widget < ActiveRecord::Base | |
# initialized contstant for the validator | |
VALID_COLORS = %(red white blue) | |
belongs_to :box | |
has_many :categorizations | |
has_many :categories, :through => :categorizations | |
validates_presence_of :name | |
validates_length_of :name, :minimum => 3 | |
validates_numericality_of :size | |
validates :color, :inclusion => { :in => VALID_COLORS, | |
:message => "can only be red white or blue" } | |
before_validation :downcase_color | |
def downcase_color | |
self.color.downcase! | |
end | |
def category_names | |
categories.map {|c| c.cat_name}.to_sentence | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment