Steve
Steve

Reputation: 2666

How to format a number 2 decimal places in rails helper

I am trying to format a number to either a currency or 2 decimal places within a rails helper (app/helpers/emails_helper.rb)

module EmailsHelper
  def email_message(invoice)
    message = "PO: #{invoice.po_number}\nAmount: #{number_to_currency(invoice.total)}"
    return message
  end
end

When I try this I get the following error:

undefined method `number_to_currency' for #<EmailsController:0x00000102b88640>

I'm assuming this is because the file is a rb and not an erb but not sure how to handle.

Upvotes: 0

Views: 823

Answers (1)

cdesrosiers
cdesrosiers

Reputation: 8892

Try importing the NumberHelper module:

module EmailsHelper
  include ActionView::Helpers::NumberHelper
  ...
end

Upvotes: 4

Related Questions