socialforge/app/models/game.rb

27 lines
893 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 => 'created_at desc'
attr_accessible :myshixun_id, :user_id, :status, :final_score, :challenge_id
belongs_to :myshixun,:touch=> true
belongs_to :user
belongs_to :challenge
has_many :outputs, :dependent => :destroy
has_many :test_sets, :dependent => :destroy
has_many :challenge_samples, :dependent => :destroy
def next_game
challenge = self.challenge
next_challenge_id = challenge.next_challenge
game = Game.where(:myshixun_id => self.myshixun_id, :challenge_id => next_challenge_id).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