Commit 1baa290231263a1ec0a6e04c8e1465aaac91b9e1

Authored by Pius Uzamere
1 parent c3e259d6

show clicks latest first

app/controllers/choices_controller.rb
@@ -5,11 +5,11 @@ class ChoicesController < InheritedResources::Base @@ -5,11 +5,11 @@ 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!}  
9 if params[:limit] 8 if params[:limit]
10 @question = Question.find(params[:question_id])#, :include => :choices) 9 @question = Question.find(params[:question_id])#, :include => :choices)
11 @question.reload 10 @question.reload
12 @choices = Choice.find(:all, :conditions => {:question_id => @question.id}, :limit => params[:limit].to_i, :order => 'score DESC') 11 @choices = Choice.find(:all, :conditions => {:question_id => @question.id}, :limit => params[:limit].to_i, :order => 'score DESC')
  12 + @choices.each {|c| c.compute_score!}
13 else 13 else
14 @question = Question.find(params[:question_id], :include => :choices) #eagerloads ALL choices 14 @question = Question.find(params[:question_id], :include => :choices) #eagerloads ALL choices
15 @choices = @question.choices(true) 15 @choices = @question.choices(true)
app/controllers/clicks_controller.rb
@@ -2,7 +2,7 @@ class ClicksController < ApplicationController @@ -2,7 +2,7 @@ class ClicksController < ApplicationController
2 # GET /clicks 2 # GET /clicks
3 # GET /clicks.xml 3 # GET /clicks.xml
4 def index 4 def index
5 - @clicks = Click.all 5 + @clicks = Click.find(:all, :order => 'created_at DESC')
6 6
7 respond_to do |format| 7 respond_to do |format|
8 format.html # index.html.erb 8 format.html # index.html.erb