Sha256: 5c58b255a771e01a4809b7c09535b1d1592a799582205bc8c0aa889270d6d857

Contents?: true

Size: 612 Bytes

Versions: 3

Compression:

Stored size: 612 Bytes

Contents

class Item < ActiveRecord::Base
  belongs_to :category

  # validations
  
  def before_validation
    self.title = "" if self.title.nil?
    self.amount = 0 if self.amount.blank?
  end

  validates_presence_of :date

  validates_presence_of :amount, :position
  validates_numericality_of :amount, :position

  def self.find_conflict(item)
    item.type.constantize.find_conflict(item)
  end

  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
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
moneyrail-0.1.5 app/models/item.rb
moneyrail-0.1.4 app/models/item.rb
moneyrail-0.1.2 app/models/item.rb