Skip to content

Instantly share code, notes, and snippets.

View jefferyf's full-sized avatar

Jeff Miller jefferyf

  • Minneapolis, MN
View GitHub Profile
@jefferyf
jefferyf / squeel_where.rb
Created August 31, 2012 15:11
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?
@jefferyf
jefferyf / mcd_converter.rb
Created June 20, 2012 20:21
Monthly Consumption Details Conversion
ConsumptionDetail.find_in_batches(:batch_size => 500, :start => 208771) do |cd_batch|
cd_batch.each{ |cd|
cd.save(:validate => false); puts "ID: #{cd.id.to_s} ~ BUILDING NAME: #{cd.energy_source.property.name}"
}
end