Commit c3e259d6424b39421abf612478fb71cc021c7f29

Authored by Pius Uzamere
1 parent e815ffbe

recompute score before returning results

app/controllers/choices_controller.rb
@@ -5,6 +5,7 @@ class ChoicesController < InheritedResources::Base @@ -5,6 +5,7 @@ class ChoicesController < InheritedResources::Base
5 has_scope :active, :boolean => true, :only => :index 5 has_scope :active, :boolean => true, :only => :index
6 6
7 def index 7 def index
  8 + Choice.all.each {|c| c.compute_score!}
8 if params[:limit] 9 if params[:limit]
9 @question = Question.find(params[:question_id])#, :include => :choices) 10 @question = Question.find(params[:question_id])#, :include => :choices)
10 @question.reload 11 @question.reload
app/models/choice.rb
@@ -55,6 +55,11 @@ class Choice < ActiveRecord::Base @@ -55,6 +55,11 @@ class Choice < ActiveRecord::Base
55 end 55 end
56 end 56 end
57 57
  58 + def compute_score!
  59 + self.score = compute_score
  60 + save!
  61 + end
  62 +
58 protected 63 protected
59 64
60 65