From 5883f6f9cc7c9a985ba489c067b560f3898b6b9a Mon Sep 17 00:00:00 2001 From: Pius Uzamere Date: Thu, 10 Dec 2009 17:23:46 -0500 Subject: [PATCH] fast, correct random prompt picking --- .gems | 1 - app/models/question.rb | 10 ++-------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/.gems b/.gems index a7bca95..a5c57bf 100644 --- a/.gems +++ b/.gems @@ -8,4 +8,3 @@ justinfrench-formtastic --version '0.2.2' --source gems.github.com thoughtbot-clearance --version '0.8.2' --source gems.github.com josevalim-inherited_resources --version '0.9.1' --source gems.github.com activemerchant --version 1.4.2' - diff --git a/app/models/question.rb b/app/models/question.rb index 4510d3e..3ad8f8b 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -22,20 +22,14 @@ class Question < ActiveRecord::Base end def picked_prompt - pc = self.prompts_count < 1 ? 2 : self.prompts_count begin - @p = prompts.find(rand(pc-1) + prompts.first.id) + @p = prompts.first(:order => 'RANDOM()') end until @p.active? return @p end - def picked_prompt_id - pc = self.prompts_count < 1 ? 2 : self.prompts_count - begin - @i = rand(pc-1) + prompts.first.id #try caching this first prompt value at some point - end until prompts.find(@i).active? - return @i + picked_prompt.id end def left_choice_text(prompt = nil) -- libgit2 0.21.2