Created
August 15, 2008 23:11
-
-
Save technoweenie/5674 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Status < ActiveRecord::Base | |
can_search do | |
scoped_by :user | |
scoped_by :created, :scope => :date_range | |
end | |
# user_id can be an integer or nil | |
def self.filter(user_id, filter, options = {}) | |
# filter can be :daily, :monthly, etc, | |
# see DateRangeScope in can_serach plugin | |
range = filter ? date_range_for(filter, options[:date]) : nil | |
# you don't have to grab the range here though, you can just use | |
# :created => {:period => filter, :start => options[:date]} | |
# i use the returned range in the view so i can display "Month Statuses" | |
records = search :created => range, :user => user_id, | |
:order => 'statuses.created_at desc', :page => options[:page], :per_page => options[:per_page] | |
[records, range] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment