Brian H. wrote:
As previously stated, those are view helpers. Models really shouldn’t
any formatting data in them at all… your view layer should do that for
But explain why you want to do number_to_currency in the model (remember
this renders a string) and there may be a way to solve your problem. You
can get number_to_currency working in the model – I’ve done it before
it’s not a good approach.
Thanks - I’m fairly new to rails, so maybe i’m going about this in the
I have a Product model with min_price and max_price properties.
In many places throughout the site, I need to display a price range. I
had this in my application_helper:
if min == max
price_range_text = number_to_currency(max)
price_range_text = number_to_currency(min)+ ’ - ’ +
But I thought it would be nice to make this an accesible value on my
Product model, so in my view I could just say <%=product.price_range%>
as opposed to <%=get_price_range(product.min_price,product.max_price)%>
So I tried adding this to my Product Model:
if self.min_price == self.max_price
price_range_text = number_to_currency(self.max_price)
price_range_text = number_to_currency(self.min_price)+ ’ - ’ +
But apparently I shouldn’t be doing this?