class CompetitionStaff < ActiveRecord::Base default_scope order: 'position asc' attr_accessible :minimum, :maximum, :category, :position belongs_to :competition validates :position, numericality: { only_integer: true } validates :minimum, numericality: { only_integer: true, greater_than_or_equal_to: 0 } validates :maximum, numericality: { only_integer: true, greater_than_or_equal_to: lambda { |obj| obj.minimum } } validates :category, presence: true, inclusion: { in: %w(all teacher student profession) } def category_text I18n.t("competition_staff.category.#{category}", locale: 'zh') end def self.category_options %w(all teacher student profession).map do |category| [I18n.t("competition_staff.category.#{category}", locale: 'zh'), category] end end end