Skip to content

Instantly share code, notes, and snippets.

@jefferyf
Created August 31, 2012 15:11
Show Gist options
  • Save jefferyf/3554311 to your computer and use it in GitHub Desktop.
Save jefferyf/3554311 to your computer and use it in GitHub Desktop.
Conditional where clause generation with squeel
# Class method on Intakes model
def self.find_for_report(options={})
joins{intake_grant}.
where do
conditions = {}
conditions[pending.eq] = false
conditions[intake_grant_id] = options[:grant_id] unless options[:grant_id].blank?
conditions[intake_date.gt] = options[:from] unless options[:from].blank?
conditions[intake_date.lt] = options[:to] unless options[:to].blank?
conditions
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment