diff --git a/app/models/choice.rb b/app/models/choice.rb index 75cf777..589bc07 100644 --- a/app/models/choice.rb +++ b/app/models/choice.rb @@ -11,6 +11,7 @@ class Choice < ActiveRecord::Base has_many :votes, :as => :voteable has_many :prompts_on_the_left, :class_name => "Prompt", :foreign_key => "left_choice_id" has_many :prompts_on_the_right, :class_name => "Prompt", :foreign_key => "right_choice_id" + named_scope :active, :conditions => { :active => true } attr_accessor :data diff --git a/app/models/prompt.rb b/app/models/prompt.rb index f31056e..706b5c4 100644 --- a/app/models/prompt.rb +++ b/app/models/prompt.rb @@ -16,13 +16,13 @@ class Prompt < ActiveRecord::Base #named_scope :voted_on_by, :include => :choices, :conditions => #named_scope :voted_on_by, proc {|u| { :conditions => { :methodology => methodology } } } + named_scope :active, :include => [:left_choice, :right_choice], :conditions => { 'left_choice.active' => true, 'right_choice.active' => true } + + def self.voted_on_by(u) select {|z| z.voted_on_by_user?(u)} end - - named_scope :visible, :include => :category, :conditions => { 'categories.hidden' => false } - validates_presence_of :left_choice, :on => :create, :message => "can't be blank" validates_presence_of :right_choice, :on => :create, :message => "can't be blank" @@ -45,7 +45,11 @@ class Prompt < ActiveRecord::Base def right_choice_id right_choice.id end - + + def active? + left_choice.active? and right_choice.active? + end + def right_choice_text(prompt = nil) right_choice.item.data diff --git a/app/models/question.rb b/app/models/question.rb index 0157cc3..670c8a4 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -22,12 +22,15 @@ class Question < ActiveRecord::Base end def picked_prompt - #prompts[rand(prompts.count-1)]#Prompt.find(picked_prompt_id) - Prompt.find(rand(prompts_count-1)) + begin + return p = Prompt.find(rand(prompts_count-1)) + end until p.active? end def picked_prompt_id - rand(prompts_count-1) + begin + return i = rand(prompts_count-1) + end until Prompt.find(i).active? end def left_choice_text(prompt = nil) -- libgit2 0.21.2