I'm trying to pass a value calculated in my controller to a model method and use it in a SELECT query.
I calc a value and want to pass it as an argument to the method below as 'control' and use it in place of the .02 in the sum calculations. The query below works as is, but if I add a third argument, call it 'control' and try to use it in the sum calc it fails. I tried it as I did with the bom and eom values by sticking {:control => control} on to the SELECT statement after the quote and before the parenthesis. The error output shows me that that :control is equal to the value passed in, but it errors on the rest of the instances of :control in the SELECT statement. The DB is PostgreSQL.
def self.rolling_total_month(bom, eom)
select("SUM((usages.usg_amount * materials.mat_voc_with)/2000) AS uc_emit_tons,
SUM(((.02) * usages.usg_amount * materials.mat_voc_with)/2000) AS c_emit_tons,
SUM((.02) * (usages.usg_amount * materials.mat_pounds_per_gal)/2000) AS hap_tons
").
joins("JOIN materials ON usages.material_id = materials.id").
where("usages.material_id <> 65 AND materials.mat_active_flag = TRUE AND materials.mat_report_flag = TRUE AND :bom <= usages.usg_date AND usages.usg_date <= :eom", { :bom => bom, :eom => eom })
end