Since update to Rails 5.2/Ruby 2.5, Date param is saved to today regardless
bnwpro opened this issue · comments
I've been using this excellent gem with great results until I updated my Rails from Edge 5.2rc2 to the official 5.2 release AND I just updated Ruby to 5.2.1.
I'm using the following in a form:
<%= form.date_field :event_start, id: :start_date, class: 'form-control', required: true %>
<%= form.time_select :event_start,
{id: :start_time,
combined: true,
prompt: 'Start time',
minute_interval: 15,
time_separator: "",
start_hour: 12,
start_minute: 00,
ampm: true},
{class: 'custom-select'} %>
<%= form.time_select :event_end,
{id: :end_time,
combined: true, ...etc. %>
In the controller Create/Update actions:
params[:event].parse_time_select! :event_start
params[:event].parse_time_select! :event_end
Since updating Rails/Ruby, time_select fields are saved correctly but the date_field defaults to today's date.
The params hash looks like:
{"utf8"=>"✓", "_method"=>"patch", "event"=>{"event_start"=>"2018-04-30", "event_start(5i)"=>"18:30:00", "event_end(5i)"=>"21:30:00"...
After updating the record, the start date is set to 2018-04-17 (today). Times are saved correctly.
I solved the issue by changing:
<%= form.date_field ...
to
<%= form.date_select ...
Again, this wasn't necessary until I updated to the above Rails/Ruby version.
Hope this helps someone out!
Thanks for posting the solution @bnwpro! I will update the docs to mention it.
date_field is just a regular input with type="date"
so it wouldn't pass in the proper params that multi-select fields do.