Forum: Ruby on Rails Where to place a global function

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C9af522fc39d5de90f21119543c2b9ab?d=identicon&s=25 Steve Litt (Guest)
on 2006-01-06 20:42
(Received via mailing list)
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 Litt
Author:
   * Universal Troubleshooting Process courseware
   * Troubleshooting Techniques of the Successful Technologist
   * Rapid Learning: Secret Weapon of the Successful Technologist
Webmaster
   * Troubleshooters.Com
   * http://www.troubleshooters.com
05d703f649ef1d07e78d7b479fb4c4ac?d=identicon&s=25 James Adam (Guest)
on 2006-01-06 20:45
(Received via mailing list)
/app/helpers/application_helper.rb

- james
C9af522fc39d5de90f21119543c2b9ab?d=identicon&s=25 Steve Litt (Guest)
on 2006-01-06 21:22
(Received via mailing list)
Thanks James,

Confirmed! It worked perfectly placing it where you suggested.

SteveT
55a3d4a1ddc93ed9f519642f669da5f2?d=identicon&s=25 Lance England (Guest)
on 2006-01-06 21:31
(Received via mailing list)
I did the same thing until I realized it was built in:

http://api.rubyonrails.com/classes/ActionView/Help...
This topic is locked and can not be replied to.