format

Change Default Date Format in Ruby on Rails

Just a quick and simple hint!
 
If you need to set the default formatting of dates throughout your whole application in Ruby on Rails, just add the following line to your "<your application>/config/environment.rb"
 
 
my_date_formats = { :default => '%d/%m/%Y' } ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!(my_date_formats) ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS.merge!(my_date_formats)
 

Format Currency in Ruby on Rails

I was looking for a way to display currency data coming from the database as a long. I found out that Ruby on Rails has a buil-in Module Helper method called ActionView::Helpers::NumberHelper:number_to_currency which allows one to format a number according to some options:
 

Syndicate content