From c3e259d6424b39421abf612478fb71cc021c7f29 Mon Sep 17 00:00:00 2001 From: Pius Uzamere Date: Thu, 3 Dec 2009 22:28:51 -0500 Subject: [PATCH] recompute score before returning results --- app/controllers/choices_controller.rb | 1 + app/models/choice.rb | 5 +++++ 2 files changed, 6 insertions(+), 0 deletions(-) diff --git a/app/controllers/choices_controller.rb b/app/controllers/choices_controller.rb index 2ed1d0f..565f7e0 100644 --- a/app/controllers/choices_controller.rb +++ b/app/controllers/choices_controller.rb @@ -5,6 +5,7 @@ class ChoicesController < InheritedResources::Base has_scope :active, :boolean => true, :only => :index def index + Choice.all.each {|c| c.compute_score!} if params[:limit] @question = Question.find(params[:question_id])#, :include => :choices) @question.reload diff --git a/app/models/choice.rb b/app/models/choice.rb index 77b3871..3d57c38 100644 --- a/app/models/choice.rb +++ b/app/models/choice.rb @@ -55,6 +55,11 @@ class Choice < ActiveRecord::Base end end + def compute_score! + self.score = compute_score + save! + end + protected -- libgit2 0.21.2