educoder/app/models/challenge_choose.rb

19 lines
593 B
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

class ChallengeChoose < ActiveRecord::Base
# attr_accessible :title, :body
# category 1 单选, 2多选
# standard_answer 正确答案 answer 答题的思路
default_scope :order => 'position'
belongs_to :challenge
has_many :challenge_tags, :dependent => :destroy
has_many :challenge_questions, :dependent => :destroy
has_one :choose_outputs, :dependent => :destroy
validates_presence_of :subject
# 判断当前用户是否答题
def current_choose_outputs
ChooseOutputs.where(:challenge_choose_id => self.id, :user_id => User.current.id).first
end
end