Skip to content

Instantly share code, notes, and snippets.

@Papillard
Created July 17, 2013 14:24
Show Gist options
  • Select an option

  • Save Papillard/6021004 to your computer and use it in GitHub Desktop.

Select an option

Save Papillard/6021004 to your computer and use it in GitHub Desktop.
scope your frequent requests
# Final
class Following < ActiveRecord::Base
$scope :recent, lambda { where(:user_id => current_user.id).where(['created_at > ?', 2.days.ago]) }
end
class UserController < ApplicationController
def index
@followings = current_user.followings.recent
end
end
# Initial
class Following < ActiveRecord::Base
end
class UserController < ApplicationController
def index
@followings = Following.where(:user_id => current_user.id).where(['created_at > ?', 2.days.ago])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment