27 lines
893 B
Ruby
27 lines
893 B
Ruby
class Game < ActiveRecord::Base
|
||
# stauts 0: can exe 1:doing 2:successed 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
|