You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
educoder/app/models/hack.rb

27 lines
493 B

class Hack < ApplicationRecord
# 编程题
validates_length_of :name, maximum: 60
# 测试集
has_many :hack_sets, ->{order("position asc")}, :dependent => :destroy
# 代码
has_many :hack_codes, :dependent => :destroy
def language
if hack_codes.count == 1
hack_codes.first.language
else
hack_codes.pluck(:language)
end
end
def code
if hack_codes.count == 1
hack_codes.first.code
else
hack_codes.pluck(:code)
end
end
end