Where to place a global function

Hi all,

I have a little function called format_price(price) that simply formats
the
argument as a dollar sign, dollar amount, dot and penny amount. Then, in
a .rhtml file, I could do this:

<%= format_price(item.unit_price * item.quantity) %>

But where do I put the format_price() function definition? The app
couldn’t
find it in app/controllers/application.rb. Where do I put it so it’s
available to all views?

Thanks

SteveT

Steve L.
Author:

/app/helpers/application_helper.rb

  • james

I did the same thing until I realized it was built in:

http://api.rubyonrails.com/classes/ActionView/Helpers/NumberHelper.html

Thanks James,

Confirmed! It worked perfectly placing it where you suggested.

SteveT

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs