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
17 18 19 |
# File 'app/models/item.rb', line 17 def self.find_conflict(item) item.type.constantize.find_conflict(item) end |
Instance Method Details
#before_validation ⇒ Object
validations
6 7 8 9 10 |
# File 'app/models/item.rb', line 6 def before_validation self.title = "" if self.title.nil? self.amount = 0 if self.amount.blank? self.position = find_position if self.position.nil? end |
#validate ⇒ Object
21 22 23 24 25 26 |
# File 'app/models/item.rb', line 21 def validate # 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 |