parent
c2dee3b831
commit
070be6e895
@ -0,0 +1,22 @@
|
||||
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: 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
|
@ -0,0 +1,7 @@
|
||||
'zh':
|
||||
competition_staff:
|
||||
category:
|
||||
all: 不限
|
||||
teacher: 教师
|
||||
student: 学生
|
||||
profession: 专业人士
|
@ -0,0 +1,13 @@
|
||||
class CreateCompetitionStaffs < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :competition_staffs do |t|
|
||||
t.references :competition
|
||||
t.integer :position
|
||||
t.string :category
|
||||
t.integer :minimum
|
||||
t.integer :maximum
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in new issue