Commit f9eb05535acad98d06326906e09b8f0fbce00bdf

Authored by Pius Uzamere
1 parent 672738b7

fix for potential error where a randomly picked prompt is for another question

Showing 1 changed file with 7 additions and 4 deletions   Show diff stats
app/models/question.rb
@@ -21,17 +21,20 @@ class Question < ActiveRecord::Base @@ -21,17 +21,20 @@ class Question < ActiveRecord::Base
21 choices_count 21 choices_count
22 end 22 end
23 23
  24 + def range_rand(min,max)
  25 + min + rand(max-min)
  26 + end
  27 +
  28 +
24 def picked_prompt 29 def picked_prompt
25 begin 30 begin
26 - pc = self.prompts_count == 0 ? 2 : self.prompts_count  
27 - return p = prompts.find(pc) 31 + return p = prompts.find(prompt_ids.rand)
28 end until p.active? 32 end until p.active?
29 end 33 end
30 34
31 def picked_prompt_id 35 def picked_prompt_id
32 begin 36 begin
33 - pc = self.prompts_count == 0 ? 2 : self.prompts_count  
34 - return i = rand(pc-1) 37 + return i = prompt_ids.rand
35 end until prompts.find(i).active? 38 end until prompts.find(i).active?
36 end 39 end
37 40