Rails 4 +简单表格:时间选择不会保持空白

时间:2017-04-04 18:55:26

标签: ruby-on-rails datetime ruby-on-rails-4 simple-form

我有一张表格:

<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: truedefault: 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被接受?

0 个答案:

没有答案