![](/img/trans.png)
[英]Hidden date field setting attributes to nil in rails console (but not in the database)
[英]Rails DateTime field has current date/time if nil in the database
我有一个带有datetime
字段的表单。 由于Rails 3.2.13尚不支持type="datetime-local"
input
字段(并且我还不准备移至4.0 beta),因此我将手动执行此操作:
<input type="datetime-local" name="person[my_date_time]"<% if @person.my_date_time %> value="<%=@person.my_date_time.strftime('%FT%T')%>"<% end %>/>
问题是@ person.my_date_time将是当前日期/时间(如果在数据库中nil
。 而且它的输出也以秒为单位,这加深了Chrome对日期时间的处理。 我想那场是空的,如果它是nil
到数据库中。 我怎么知道? Rails的datetime_select
方法以我想要的方式处理它。
如果数据库中的datetime字段为nil
,则您的应用程序中的某些内容必须正在更改或覆盖该值。 也许您在某处有默认值? 在没有看到比现在发布的更多的代码的情况下,真的不可能说出正在发生的事情。 可以为您的Person
模型发布代码以及任何其他相关代码(任何可能影响事物的宝石等)吗?
strftime("%FT%R") # Will output without seconds, e.g. "2013-04-18T21:43"
http://www.ruby-doc.org/core-1.9.3/Time.html#method-i-strftime
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.