[英]How to use the date_select and time_select in the form in rails?
我的数据库表中分别有一个“ Date
和Time
列。 当我单击表中的“编辑”时,“ Date
和Time
应按params
显示值。 用户可以更改Date
和Time
并更新form
。
我尝试了以下方法:
<div class="field">
<%= f.label :Sent_Date, 'Sent Date:' %>
<%= date_select(:Appointment_Date, object: f.object) %>
</div>
<div class="field">
<%= f.label :Appointment_Time, 'Appointment Time:' %>
<%= f.time_select(:history, :Appointment_Time, include_seconds: true) %>
</div>
它不能正确显示值,也不会更改为下一条记录。 显示选择值。 我需要在这里转换日期吗? 因为,在数据库中,它的值就像2013/05/13
而在字段中的值就像2013/05/13
20 December 2013
Time
字段不起作用。 请建议我如何解决此问题。
谢谢
不要将常量用作模型的字段。 以大写字母开头的任何变量都将被视为常量,并且常量不可更改。 Ruby会warning: already initialized constant
您warning: already initialized constant
在尝试更改常量值时warning: already initialized constant
,因此这可能是您无法更改时间和日期的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.