Skip to content

Instantly share code, notes, and snippets.

@ka8725
Created April 10, 2012 13:30
Show Gist options
  • Save ka8725/2351391 to your computer and use it in GitHub Desktop.
Save ka8725/2351391 to your computer and use it in GitHub Desktop.
def self.search(params)
orders = self
orders = orders.scoped(:conditions => {:service_type => params[:service_type]}) if params[:service_type].present?
orders = orders.scoped(:conditions => ['orders.created_at >= ?', params[:date_range_start]]) if params[:date_range_start].present?
orders = orders.scoped(:conditions => ['orders.created_at <= ?', params[:date_range_end]]) if params[:date_range_end].present?
orders.all
end
@avsej
Copy link

avsej commented Apr 10, 2012

def self.search(params)
  returning self.scoped do |orders|
    orders.apply_finder_options(:conditions => {:service_type => params[:service_type]}) if params[:service_type].present?
    orders.apply_finder_options(:conditions => ['orders.created_at >= ?', params[:date_range_start]]) if params[:date_range_start].present?
    orders.apply_finder_options(:conditions => ['orders.created_at <= ?', params[:date_range_end]]) if params[:date_range_end].present?
  end.all
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment