mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
14 lines
452 B
Ruby
14 lines
452 B
Ruby
# frozen_string_literal: true
|
|
|
|
class Resource < ApplicationRecord
|
|
belongs_to :conference
|
|
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
|
|
|
|
private
|
|
|
|
def used_no_more_than_quantity
|
|
errors.add(:used, 'cannot be higher than total quantity') if used.present? && quantity.present? && used > quantity
|
|
end
|
|
end
|