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
/app/helpers/application_helper.rb - james On 1/6/06, Steve Litt <slitt@troubleshooters.com> wrote:> 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 > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Thanks James, Confirmed! It worked perfectly placing it where you suggested. SteveT On Friday 06 January 2006 02:44 pm, James Adam wrote:> /app/helpers/application_helper.rb > > - james > > On 1/6/06, Steve Litt <slitt@troubleshooters.com> wrote: > > 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
I did the same thing until I realized it was built in: http://api.rubyonrails.com/classes/ActionView/Helpers/NumberHelper.html On 1/6/06, Steve Litt <slitt@troubleshooters.com> wrote:> 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 > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >