My user wants to use the date format% d /% m /% Y (for example: 02/26/2011).
To display dates correctly, I therefore changed to: the default format in environment.rb:
environment.rb :
ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS.merge!(
:default => "%d/%m/%Y"
)
It works fine, but I have one problem when trying to save date strings entered in this format in the database.
It seems that the rails take the lines formed with% m /% d /% Y instead of% d /% m /% Y
04/02/2011 is saved as 2011-04-02 and 26/02/2011 is simply invalid and not saved. ..
I was looking for solutions for this, but the ones I found rely on date changes in my models, such as:
mymodel.rb :
def datefield_formatted
datefield.strftime '%m/%d/%Y'
end
def datefield_formatted=(value)
self.datefield = Time.parse(value)
end
view.html.erb :
<%= form.input :datefield_formatted %>
, ( ).
, Rails "" % d/% m/% Y .