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/exercise_question.rb

47 lines
1.2 KiB

6 years ago
#encoding: utf-8
class ExerciseQuestion < ApplicationRecord
belongs_to :exercise
belongs_to :shixun, optional: true
6 years ago
has_many :exercise_choices, :dependent => :delete_all
has_many :exercise_answers
6 years ago
has_many :exercise_shixun_challenges, :dependent => :delete_all
has_many :exercise_shixun_answers
has_many :exercise_answer_comments
has_many :exercise_standard_answers
6 years ago
scope :insert_question_ex, lambda {|k| where("question_number > ?",k)}
scope :find_by_custom, lambda {|k,v| where("#{k} = ?",v)} #根据传入的参数查找问题
scope :left_question_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题
scope :find_objective_questions, -> {where("question_type != ?",4)} #查找全部客观题
6 years ago
def question_type_name
case self.question_type
when 0
"单选题"
when 1
"多选题"
when 2
"判断题"
when 3
"填空题"
when 4
"简答题"
when 5
"实训题"
end
end
#获取问题的全部标准答案
def get_standard_answer_ids
exercise_standard_answers.pluck(:exercise_choice_id)
end
def get_standard_answer_text
exercise_standard_answers.pluck(:answer_text)
end
end