I have a :dob
(date of birth) attribute and if I if I call it in a view it appears in a YYYY-MM-DD
format. Where can I set the default to a MM-DD-YYYY
or some other variation? I would prefer to have it as "January 28th, 1990" and can do that in the view with dob.to_formatted_s(:long_ordinal)
but would prefer to have a default to keep the code in my view a little nicer.
Asked
Active
Viewed 944 times
2

Alok Swain
- 6,409
- 5
- 36
- 57

user3245766
- 57
- 4
-
the same type http://stackoverflow.com/questions/7145152/change-default-date-format-in-ruby-on-rails – Rajarshi Das Apr 09 '14 at 08:30
2 Answers
4
# config/initializers/date_formats.rb
Date::DATE_FORMATS[:default] = "%m/%d/%Y"

Alok Anand
- 3,346
- 1
- 20
- 17
1
You can change the format by overriding the default date format for ActiveSupport.
In config/environment.rb
add this line
Date::DATE_FORMATS.merge!(:default => "%m/%d/%Y")

Alok Swain
- 6,409
- 5
- 36
- 57