On p. 93, AWDWR(3rd) it says,

--------
...we could do this:

<span><%= sprintf("$0.02f", product.price) %</span>

This would work, but it embeds knowledge of currency formatting into the
view.  Should we want to internationalize the application later, this
would be a maintenance problem.
---------


<Goody.  Let's move the formatting out of the view and into a more
centralized location.  The Product model?  Hmm...maybe, but not all
calls to the Product model will want the number converted to a formatted
string.  The ProductsController then?  Yes, yes.  That must be it!>

<turn the page>


--------
Instead, let's use a helper method to format the price as a currency.
...
...
<span><%= number_to_currency(product.price) %</span>
--------

Wt??  How does that solve any maintenance issues.  If I later want to
change the view to display a different format, what's the difference
between having to change the parameters of number_to_currency()
everywhere it appears vs. changing the format of sprintf()?
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to