Date Formats in ActiveRecord / Rails 3

In my model, I have departure_date and return_date.

I use a text box instead of date_select so that I can use jQuery dumping.

My application is currently based in the USA, but I hope to get international members.

So basically this is what happens. User type (USA) on a date such as April 4, 2010 (April 1).

Of course, MySQL stores it as a date, for example 2010-04-01 ...

In any case, when the user proceeds to edit the date later, he shows "01/04/2010" because I use strftime ("% m /% d /% Y"), which does not make sense ... and thinks that it is January 4, and not the original on April 1.

This, as the only way to accurately store data, is to enter the user: 2010-04-01

Hope this all makes sense. What I'm really doing is a way for the user to enter (or use datepicker) the date in their native format.

Thus, someone from Europe can dial 04/01/2010 on April 1, but someone from the United States would print on 04/01/2010.

Is there a simple, elegant solution?

Thanks for any suggestions.

+3
source share
1 answer

I have run into the same issue recently.

My site is based in France, so I need to save the date as a date in French.

I also use jQuery DatePicker.

To do this, I install I18n.locale in the visitor's country. For instance:

I18.locale = :fr

before_filter _

/fr.yml

, , JqueryDatePicket.

, :

$.datepicker.formatDate('dd-mm-yyyy');

datepicker.

locale/fr.yml

!

, !

+2

Source: https://habr.com/ru/post/1748152/


All Articles