Adding a list of some of the Rails formatting helpers I often have to use:
- Converting a number to a dollar amount -> number_to_currency(field_value)
- Changing the date to US date format (MM/DD/YYYY) -> field_value.strftime(“%m/%d/%Y”)
- Converting to a percentage -> number_to_percentage(field_value)
For additional helpers with numbers here’s the link to the Rails API for number helpers
I needed help in formatting time in Rails and found here in the strftime( string ) → string section. In particular, I wanted to change the default timestamp (created_at) to an American format MM/DD/YYYY.
My dates were displaying DD-MM-YYYY, but I wanted to display it MM/DD/YYYY.
Here’s an easy way to do that.