[Rails 3.1.3 / ruby 1.9.2 ]
I am trying to manage localized dates and I don''t actually understand
how it''s managed w Rails 3.1 ... I thought there was no more issues w
I18n..
my locale is defined : I18n.locale => :fr
I am using a localized version of jQuery DatePicker , so it displays
selected dates in the text field like : 01/02/2012 (Feb first )
i.e. ( in generated html):
<input id="start_shooting_date" class="text
hasDatepicker" type="text" value="01/02/2012" name="project[start_shooting_date]">
in my Project model , date validations are OK, then I store the
updated project
@project.update_attributes(params[:project])
and I get stored in the DB : start_shooting_date: "2012-01-02
00:00:00" (Jan 2nd) rather than "2012-02-01 00:00:00" ( Feb
first )
I''ll appreciated your feedback ...
I defined in environment.rb ( don''t know if necessary.. for input .
but it seems to be for output, or is it redundant with defaults .yml
files ?)
# if locale french
Date::DATE_FORMATS.merge!( :default => "%d/%m/%Y" )
I also defined the I18n default format in the .yml files
fr:
date:
formats:
default: "%d/%m/%Y"
short: "%e %b"
long: "%e %B %Y"
full: "%A %d %B %Y"
time:
formats:
default: "%d %B %Y %H:%M:%S"
short: "%d %b %H:%M"
long: "%A %d %B %Y %H:%M"
am: ''am''
pm: ''pm''
en:
date:
formats:
default: "%Y-%m-%d"
short: "%b %d"
long: "%B %d, %Y"
full: "%A %B %d, %Y"
time:
formats:
default: "%a, %d %b %Y %H:%M:%S %z"
short: "%d %b %H:%M"
long: "%B %d, %Y %H:%M"
am: "am"
pm: "pm"
--
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Erwin
2012-Jan-29 08:01 UTC
Re: trouble in storing dates from localized form text fields...
[SOLVED] don''t know if it''s the best solution, but it worked... changed the date text_fields to text_field_tag, on output , set the value in the controller, with I18n and local format>> @start_shooting_date = I18n.l( @project[:start_shooting_date], :format => "%d/%m/%Y")then on input , set the attribute value from the form field in the controller, with I18n and local format>> @project = Project.new(params[:project]) # on create >> @project.attributes = params[:project] # on update >> @project[:start_shooting_date] = I18n.l(params[:start_shooting_date].to_date, :format => "%d/%m/%Y") >> if @project.savethis way, the dates are correctly saved in the DB with the standard :db format but input/output in the form is in local format "dd/mm/yyyy" ( also defined like this in localized DatePicker -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.