Topic: text_field datetime format
first of all introduce myself because this is the first time I write here. I'm new to Rails and after a period of learning I'm now develping an application.
I'm from Spain, and as you know here we have different date format. I've searched a solution but haven't found a response.
I explain my case.
I've added the following to environment.rb
ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!(:default => '%d/%m/%Y %H:%M:%S')
This runs fine for list and show pages... but when I go to edit, Rails doesn't respect the format.
To solve this, I've added:
<%= text_field 'banner', 'created_at', :value => @banner.created_at.to_s %>
And this runs fine... in apparience, because is just the viewing format.
When the value is stored to the database (mysql with YYYY-MM-DD HH:MM:SS datetime format) values for month and day are inversed.
e.g. if I write 11/12/2006 => nov 11 2006 in the database I get 2006-12-11 => dec 12 2006. More over, if I write 22/11/2006 the datetime inserted in the database is 0000-00-00 00:00:00, and when I go back to the list I get a nil exception
How can I solve that?
Thanks in advance