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 23  
24 24 def picked_prompt
25 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 28 end until p.active?
28 29 end
29 30  
30 31 def picked_prompt_id
31 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 36 end
35 37  
36 38 def left_choice_text(prompt = nil)
... ...