Hi,
There are two places were you should do it:
-
Rails: Best
choice is
I18N API,
summary:
1. Get the locales you need from
https://github.com/svenfuchs/rails-i18n/tree/master/rails/locale
2. Place them in "config\locales\"
3. In "config\aplication.rb" uncomment the
lines
#
config.i18n.load_path += Dir[Rails.root.join('my', 'locales',
'*.{rb,yml}').to_s]
#
config.i18n.default_locale = :de
4. Set your default language, example for Spanish
config.i18n.default_locale = :es
5. Add an the file "nitializers\date_formats.rb"
with the content
Time::DATE_FORMATS[:default] = lambda {
|time| I18n.l(time) }
Date::DATE_FORMATS[:default] = lambda {
|date| I18n.l(date) }
6. Restart the server.
-
Datepicker: in the
place where you call it add:
$.timepicker.setDefaults($.timepicker.regional['es']);
You might want to have different regional
settings (included
date and time formats) for each users, then the best solution is to
place the regional variable in the users models (Examples in the
I18N api).
Just one last think, rails will not raise and
error if the
format is wrong, instead will save a nil value in the database.
Greetings,
El 30/09/2011 3:39, Tom Pett escribió:
I recently started using jQuery and the Datepicker
with an application
of mine.
with the help of http://railscasts.com/episodes/213-calendars
I got the
datepicker working on a text_field containing a date.
Problem however is when we edit a model. Since a text_field shows the
database value for a field by default, it displays the date as
‘2011-05-24’. When we open te datepicker on this field it defaults to
‘today’ since it cant read the current value of the field.
Picking a date will display it in the format specified of datepicker,
but saving is no problem. I guess Rails is smart enough to figure it out
between the I18n.
My question is, how can I make sure my date is displayed in the format I
want it to be in the text_field of a form when editting.
--
Miquel C. Escarré
+34 699 73 22 46
[email protected]
–
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.