socialforge/app/models/game.rb

24 lines
833 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 Game < ActiveRecord::Base
# stauts 0: can exe 1doing 2successed 3:locked
default_scope :order => 'stage'
attr_accessible :description, :myshixun_id, :stage, :subject, :user_id, :status, :ready_knowledge, :task_pass, :answer, :score, :final_score
belongs_to :myshixun,:touch=> true
belongs_to :user
has_many :outputs, :dependent => :destroy
has_many :test_sets, :dependent => :destroy
has_many :challenge_samples, :dependent => :destroy
def next_game
game = Game.where(:myshixun_id => self.myshixun_id, :stage => self.stage + 1).first
render_404 if game.nil?
return game
end
# 获取game最新的一条输出结果
def latest_output
outputs = Output.where(:game_id => self.id).order("created_at desc")
output = outputs.blank? ? nil : outputs.first
return output
end
end