I’m generating invoice PDFs on the fly, and using my model to calculate the totals. For example:
def cost
jobs.inject(0) do |sum, job|
sum + job.cost
end
end
When generating my invoice I want the following in currency:
pdf.text "Invoice Total: $#{number_to_currency(cost)}"
But when I attempt to use the number_to_currency helper in order to display the calculated values as currency, I get errors. Any advice on how/where to accomplish this? Thanks.
If you are calling the code from within your model, you will need to include the helper as they are not included in ActiveRecord::Base.
So, you might have something like this in your model code: