Skip to content

Instantly share code, notes, and snippets.

@jordinl-zz
Created December 13, 2010 13:05
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 jordinl-zz/738971 to your computer and use it in GitHub Desktop.
Save jordinl-zz/738971 to your computer and use it in GitHub Desktop.
named_scope :report_options, lambda { |params|
{
:include => :order,
:joins => [:order => [:redemption, :promo_code]],
:conditions =>
[
params[:before] ? "redemptions.created_at < '#{params[:before]}'" : nil,
params[:after] ? "redemptions.created_at > '#{params[:after]}'" : nil,
params[:promo_code] ? "promo_codes.token = '#{params[:promo_code]}'" : nil
].compact.join(" AND ")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment