28 lines
886 B
Ruby
28 lines
886 B
Ruby
class Challenge < ActiveRecord::Base
|
|
default_scope :order => 'position'
|
|
belongs_to :shixun,:touch=> true
|
|
belongs_to :user
|
|
has_many :challenge_samples, :dependent => :destroy
|
|
has_many :test_sets, :dependent => :destroy
|
|
has_many :challenge_tags, :dependent => :destroy
|
|
has_many :games, :dependent => :destroy
|
|
|
|
validates_presence_of :subject
|
|
validates_presence_of :score
|
|
validates_presence_of :task_pass
|
|
validates_length_of :subject, :maximum => 255
|
|
|
|
def next_challenge
|
|
challenge_count = Challenge.where(:shixun_id => self.shixun_id).count
|
|
render_404 if self.position ==challenge_count
|
|
Challenge.where(:position => (self.position + 1), :shixun_id => self.shixun).first
|
|
end
|
|
|
|
def last_challenge
|
|
render_404 if self.position < 2
|
|
position = self.position - 1
|
|
Challenge.where(:position => position, :shixun_id => self.shixun).first
|
|
end
|
|
|
|
end
|