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

27 lines
698 B

class PollQuestion < ApplicationRecord
belongs_to :poll
has_many :poll_answers, :dependent => :delete_all
attr_accessor :question_answers, :question_other_anser
has_many :poll_votes
scope :ques_count, lambda {|k| where("question_type = ?",k)}
scope :ques_necessary, -> {where("is_necessary = ?",1)}
scope :insert_question, lambda {|k| where("question_number > ?",k)}
validates :question_title, length: { maximum: 1000, too_long: "不能超过1000个字符" }
def question_type_name
case self.question_type
when 1
"单选题"
when 2
"多选题"
when 3
"主观题"
when 4
"多行主观题"
end
end
end