我有一张表格:
<div class="form-inline">
<div class="form-group col-sm-4 time-input mb10">
<%= f.input :wake_time, as: :time, minute_step: 15, ampm: true, include_blank: true , default: 'blank', label: "Wake Time" %>
</div>
<div class="form-group col-sm-8 mb10">
<%= f.input :wake_d, label: "Description", input_html: { class: 'form-input' }, include_blank: true %>
</div>
</div>
</div>
但是尽管有include_blank: true
和default: blank
,但在提交表单时,会生成以下SQL:
SQL (9.8ms) INSERT INTO "repositionings" ("wake_d", "wake_time") VALUES ($1, $2) RETURNING "id" [["wake_d", ""], ["wake_time", "0001-01-01 00:00:00.000000"]]
即使这两个字段都留空了。如您所见,正在插入0001-01-01 00:00:00.000000
的通用时间而不是nil
。 如何解决这个问题,以便nil
被接受?