datetime_select 上的值为零? [英] Nil value on datetime_select?

查看:32
本文介绍了datetime_select 上的值为零?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当将 <%= f.datetime_select :start %> 用于新"对象表单时,如何设置选项以不选择默认日期而是选择 nil/null 值?相关模型中的字段可以选择为空,但默认情况下 datetime_select 控件没有空选项.

解决方案

我想你想要:

f.datetime_select :start, :include_blank =>真实

start 为 nil 时,字段将选择空白选项.这也允许用户输入日期.

有关详细信息,请参阅有关 date_select 的文档.>

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 in the related model can optionally be null but by default the datetime_select control doesn't have a null option.

解决方案

I think you want:

f.datetime_select :start, :include_blank => true

When start is nil, the fields will select the blank option. This also allows users to not enter a date.

See the documentation for date_select for details.

这篇关于datetime_select 上的值为零?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆