views:

416

answers:

3

Hi There,

I've been working with a rails form all day and I was just randomly testing it and tried the date 25/12/2009 and it came up with a huge error.

It was at this point I realised that rails is set to american date mode (mm/dd/yyyy) instead of the UK style: dd/mm/yyyy.

How can I set rails to automatically deal with all dates in dd/mm/yyyy format?

+4  A: 

In your settings file: 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)

source: http://thedevelopercorner.blogspot.com/2009/03/change-default-date-format-in-ruby-on.html

Chris Ballance
this just handles output...this isn't what he's asking about.
Subimage
A: 

Take a look at this topic on Ruby Forums, you will find what you need to do this. Regards.

Nathan Campos
That link seems a little old. From 2006. I didn't have great results with it.
y0mbo
A: 

You're looking more for something like this, although that solution still isn't too elegant.

http://source.mihelac.org/2006/9/13/parsing-european-date-format-in-ruby-rails

Subimage