From f9eb05535acad98d06326906e09b8f0fbce00bdf Mon Sep 17 00:00:00 2001 From: Pius Uzamere Date: Fri, 4 Dec 2009 11:21:46 -0500 Subject: [PATCH] fix for potential error where a randomly picked prompt is for another question --- app/models/question.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/models/question.rb b/app/models/question.rb index 2d9c177..1e20933 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -21,17 +21,20 @@ class Question < ActiveRecord::Base choices_count end + def range_rand(min,max) + min + rand(max-min) + end + + def picked_prompt begin - pc = self.prompts_count == 0 ? 2 : self.prompts_count - return p = prompts.find(pc) + return p = prompts.find(prompt_ids.rand) end until p.active? end def picked_prompt_id begin - pc = self.prompts_count == 0 ? 2 : self.prompts_count - return i = rand(pc-1) + return i = prompt_ids.rand end until prompts.find(i).active? end -- libgit2 0.21.2