datetime_select上的值是多少?
当使用作为“新”对象表单时,如何将选项设置为默认情况下不选择日期,而是选择nil / null值? 相关模型中的字段可以选择为null,但默认情况下datetime_select控件没有null选项。
我想你想要:
f.datetime_select :start, :include_blank => true
当start
为nil时,字段将选择空白选项。 这也允许用户不输入日期。
有关详细信息,请参阅date_select的文档 。
您将需要使用:prompt选项。
来自Rails文档:
# Generates a datetime select with a custom prompt. Use :prompt=>true for generic prompts. datetime_select("post", "written_on", :prompt => {:day => 'Choose day', :month => 'Choose month', :year => 'Choose year'}) datetime_select("post", "written_on", :prompt => {:hour => true}) # generic prompt for hours datetime_select("post", "written_on", :prompt => true) # generic prompts for all