Is there a simple way to format your data in the .rhtml file?
I come from a PHP/Smarty background, and in the templates, I’ve used
what is called “modifiers” to format data.
{$price|currency_format} # displays in currency format
{$description|truncate:“100”} # Truncates the description after 100
characters
It seems like the template (rhtml) would be the ideal place to play with
the display format. I saw a display_currency function in one of the
other posts, and I tried including it in my application controller. It
runs fine if you call it from within the controller, but it won’t let me
call it from the rhtml file.
in application controller: (or any controller)
def display_currency(number)
unless number.nil?
“$” + sprintf("%01.2f",number)
end
end
in .rhtml file:
<% display_currency(@price) %>
Error:
undefined method `display_currency’ for #<#Class:0x39381e8:0x3938110>
Do I have to write my own functions for things like this or are there
some built in? Either way, how do I use them in the .rhtml files?
Thank you,
Brandon P.