Class: Item
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Item
- Defined in:
- app/models/item.rb
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
-
#before_validation ⇒ Object
validations.
- #validate ⇒ Object
Class Method Details
.find_conflict(item) ⇒ Object
16 17 18 |
# File 'app/models/item.rb', line 16 def self.find_conflict(item) item.type.constantize.find_conflict(item) end |
Instance Method Details
#before_validation ⇒ Object
validations
6 7 8 9 |
# File 'app/models/item.rb', line 6 def before_validation self.title = "" if self.title.nil? self.amount = 0 if self.amount.blank? end |
#validate ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/models/item.rb', line 20 def validate # validate category unless self.category && self.category.kind == self.type errors.add("category", "the category is not for #{self.type}") end # validate index of day if same = self.class.find_conflict(self) errors.add("position", "position #{position} conflicts with #{same.title} (#{same.amount}, #{same.date})") end end |