Skip to content

Commit

Permalink
Made stats page efficient.
Browse files Browse the repository at this point in the history
  • Loading branch information
threedaymonk committed Jul 13, 2009
1 parent 70f4ec0 commit 99209e8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/controllers/stats_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class StatsController < ApplicationController
def index
@articles = Article.most_voted.paginate(:page => params[:page], :include => :votes)
@articles = Article.most_voted.paginate(:page => params[:page], :include => [:votes])
end
end
4 changes: 2 additions & 2 deletions app/models/article.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ class Article < ActiveRecord::Base
named_scope :most_voted, :order => "articles.votes_count DESC"

def causes
votes.causing.map{ |v| v.things }.flatten.sort.uniq
votes.select{ |v| v.effect == "cause" }.map{ |v| v.things }.flatten.sort.uniq
end

def preventors
votes.preventing.map{ |v| v.things }.flatten.sort.uniq
votes.select{ |v| v.effect = "prevent" }.map{ |v| v.things }.flatten.sort.uniq
end
end
4 changes: 2 additions & 2 deletions app/views/stats/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
</tr>
<% @articles.each do |article| %>
<tr>
<td><%= h(truncate(article.title, 50)) %></td>
<td><%= article.votes.count %></td>
<td><%= h(truncate(article.title, :length => 50)) %></td>
<td><%= article.votes.length %></td>
<td><%= h(article.causes * ", ") %></td>
<td><%= h(article.preventors * ", ") %></td>
</tr>
Expand Down

0 comments on commit 99209e8

Please sign in to comment.