Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Dog < ActiveRecord::Base
- STATES = %w(Incomplete Complete).freeze
- validates_inclusion_of :state, :in => STATES
- before_validation_on_create :set_initial_state
- valdates_presence_of :name, :if => :complete?
- STATES.each do |state|
- define_method(:"#{state.underscore}?") do
- self.state == state
- end
- end
- protected
- def set_initial_state
- self.state ||= STATES.first
- end
- end
Add Comment
Please, Sign In to add comment