Commit eaf03aa8f88688ea60dfac30842e9940defbe0b6

Authored by Pius Uzamere
1 parent 3fe8a232

shoring up the 'active prompts only' logic

Showing 1 changed file with 6 additions and 4 deletions   Show diff stats
app/models/question.rb
@@ -24,16 +24,18 @@ class Question < ActiveRecord::Base @@ -24,16 +24,18 @@ class Question < ActiveRecord::Base
24 def picked_prompt 24 def picked_prompt
25 pc = self.prompts_count < 1 ? 2 : self.prompts_count 25 pc = self.prompts_count < 1 ? 2 : self.prompts_count
26 begin 26 begin
27 - return p = prompts.find(rand(pc-1) + prompts.first.id)  
28 - end until p.active? 27 + @p = prompts.find(rand(pc-1) + prompts.first.id)
  28 + end until @p.active?
  29 + return @p
29 end 30 end
30 31
31 32
32 def picked_prompt_id 33 def picked_prompt_id
33 pc = self.prompts_count < 1 ? 2 : self.prompts_count 34 pc = self.prompts_count < 1 ? 2 : self.prompts_count
34 begin 35 begin
35 - return i = rand(pc-1) + prompts.first.id #try caching this first prompt value at some point  
36 - end until prompts.find(i).active? 36 + @i = rand(pc-1) + prompts.first.id #try caching this first prompt value at some point
  37 + end until prompts.find(@i).active?
  38 + return @i
37 end 39 end
38 40
39 def left_choice_text(prompt = nil) 41 def left_choice_text(prompt = nil)