Skip to content

Instantly share code, notes, and snippets.

@technoweenie
Created August 15, 2008 23:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save technoweenie/5674 to your computer and use it in GitHub Desktop.
Save technoweenie/5674 to your computer and use it in GitHub Desktop.
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