Skip to content

Instantly share code, notes, and snippets.

@mickey
Created October 26, 2010 15:38
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 mickey/ddddfeddf70264a81289 to your computer and use it in GitHub Desktop.
Save mickey/ddddfeddf70264a81289 to your computer and use it in GitHub Desktop.
def search_by_filters casting_call, params, paginate = false, page = nil, per_page = 15
scopes = search_scopes casting_call, params
results = scopes.inject(self) {|m,v| m.scopes[v[0]].call(m, v[1]) }
results = results.order_by_date
(paginate) ? (results.paginate(:page => page, :per_page => per_page)) : (results)
end
def search_scopes(casting_call, params)
options = options_for_search(casting_call, params)
logger.info "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< NOT RATED BY >>>> #{options[:production_account_id].inspect}"
scopes = []
scopes << [:eager_load, '']
scopes << [:by_casting_call, options[:casting_call]]
scopes << [ :by_part, options[:part_id] ] if options[:part_id]
scopes << [:callbacks] if options[:callbacks]
if options[:label] == 'unrated'
scopes << [ :not_rated_by, options[:production_account_id] ]
elsif options[:label] != 'all'
scopes << [ :by_rate, options[:label] ]
scopes << [ :rated_by, options[:production_account_id] ]
end
scopes
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment