Commit 672738b7d893e757e090352f367f5b2f22e8f974

Authored by Pius Uzamere
1 parent ba3f5563

fix for the case in which we're picking a prompt before the prompts_count has been updated

Showing 1 changed file with 5 additions and 3 deletions   Show diff stats
app/models/question.rb
@@ -23,14 +23,16 @@ class Question < ActiveRecord::Base @@ -23,14 +23,16 @@ class Question < ActiveRecord::Base
23 23
24 def picked_prompt 24 def picked_prompt
25 begin 25 begin
26 - return p = Prompt.find(rand(prompts_count-1)) 26 + pc = self.prompts_count == 0 ? 2 : self.prompts_count
  27 + return p = prompts.find(pc)
27 end until p.active? 28 end until p.active?
28 end 29 end
29 30
30 def picked_prompt_id 31 def picked_prompt_id
31 begin 32 begin
32 - return i = rand(prompts_count-1)  
33 - end until Prompt.find(i).active? 33 + pc = self.prompts_count == 0 ? 2 : self.prompts_count
  34 + return i = rand(pc-1)
  35 + end until prompts.find(i).active?
34 end 36 end
35 37
36 def left_choice_text(prompt = nil) 38 def left_choice_text(prompt = nil)