2017-09-05 22:23:34 +03:00
|
|
|
class Resource < ApplicationRecord
|
2017-02-06 16:11:22 +05:30
|
|
|
belongs_to :conference
|
2017-03-21 16:46:09 +05:30
|
|
|
validates :name, :used, :quantity, presence: true
|
|
|
|
|
validates :used, :quantity, numericality: { greater_than_or_equal_to: 0, only_integer: true }
|
|
|
|
|
validate :used_no_more_than_quantity
|
2017-02-06 16:11:22 +05:30
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
2017-03-21 16:46:09 +05:30
|
|
|
def used_no_more_than_quantity
|
|
|
|
|
errors.add(:used, 'cannot be higher than total quantity') if used.present? && quantity.present? && used > quantity
|
2017-02-06 16:11:22 +05:30
|
|
|
end
|
|
|
|
|
end
|