In Rails3 you can run:

Date::DATE_FORMATS[:default] = "%m/%d/%Y"

skipping the ActiveSupport::CoreExtensions::...

see your installation of active support, eg:

activesupport-3.0.0.beta3/lib/active_support/core_ext/conversions.rb for 
more info.

Josh Susser wrote:
> Dav Yaginuma wrote:
>> I've spent all day digging through the rails api and postgres-pr on
>> this, I think it's time to ask the list.
>> 
>> Postgres stores a Date in YYYY-MM-DD format. My users want the dates
>> in MM/DD/YYYY format.
>> 
>> Sure, I could explicitly convert it on the app level every place where
>> a date is displayed, but that seemed like a DRY violation.
> 
> There's already a nice way to do this. ActiveSupport enhances Date#to_s 
> to take a format parameter. Fire up script/console and look at the value 
> of this hash:
> ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS
> 
> If you add an entry for :default, that will be used for all to_s 
> conversions where you don't specify a format. And you can use 
> some_date.to_s(:db) to output in the format for your database.  If you 
> want to change or add formats, put something like this in your 
> environment.rb after the end of the Initializer block:
> 
> ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!(
>   :default => '%m/%d/%Y',
>   :date_time12  => "%m/%d/%Y %I:%M%p",
>   :date_time24  => "%m/%d/%Y %H:%M",
> )
> 
> --josh
> http://blog.hasmanythrough.com

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to