Nerian / bootstrap-datepicker-rails

A Datepicker for Twitter Bootstrap, integrated with Rails assets pipeline
MIT License
648 stars 182 forks source link

Not updating database date field #130

Closed regalbob closed 6 years ago

regalbob commented 7 years ago

Great datepicker! But it doesn't update the database date field. We're at Rails 4.1.15, Ruby 2.1.9

StackOverflow says it's due to the format- but I couldn't get that to work (https://stackoverflow.com/questions/15405703/changes-in-the-form-are-not-saved-to-database)

form:

<%= form_for(document) do |f| %>
  <div class="field">
    <%= f.label "Expiration Date:" %>
     <input type="text" id="document_expiration_date" name="document[expiration_date]" data-provide='datepicker' style="width:90px;">
  </div>
  <div class="actions" style="width:150px;">
    <%= f.submit %>
  </div>
<% end %>
regalbob commented 7 years ago

This solved it (in controller): @document.expiration_date = DateTime.strptime(params[:document][:expiration_date], '%m/%d/%Y').to_date

Nerian commented 6 years ago

Hi,

I would recommend that you use simple_form; it simplifies forms quite a lot :)