diff --git a/app/controllers/asciicasts_controller.rb b/app/controllers/asciicasts_controller.rb index 4d8124a..f5b962c 100644 --- a/app/controllers/asciicasts_controller.rb +++ b/app/controllers/asciicasts_controller.rb @@ -10,8 +10,8 @@ class AsciicastsController < ApplicationController def index collection = Asciicast. + newest. includes(:user). - order("created_at DESC"). page(params[:page]). per(PER_PAGE) @@ -22,8 +22,8 @@ class AsciicastsController < ApplicationController def popular collection = Asciicast. - order("views_count DESC"). - where("views_count > 0"). + popular. + includes(:user). page(params[:page]). per(PER_PAGE) diff --git a/app/models/asciicast.rb b/app/models/asciicast.rb index d5d7bf1..0cda51b 100644 --- a/app/models/asciicast.rb +++ b/app/models/asciicast.rb @@ -12,6 +12,8 @@ class Asciicast < ActiveRecord::Base has_many :likes, :dependent => :destroy scope :featured, where(:featured => true) + scope :popular, where("views_count > 0").order("views_count DESC") + scope :newest, order("created_at DESC") before_create :assign_user, :unless => :user