Nil value on datetime_select?

后端 未结 2 1575
悲哀的现实
悲哀的现实 2021-01-17 14:24

When using <%= f.datetime_select :start %> for a \"new\" object form, how can you set the options to not select a date by default but rather a nil/null value? The field i

2条回答
  •  长发绾君心
    2021-01-17 14:48

    You'll want to use the :prompt option.

    from the Rails docs:

      # 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
    

提交回复
热议问题