简体   繁体   English

如何在rails的表单中使用date_select和time_select?

[英]How to use the date_select and time_select in the form in rails?

I have a Date and Time column separately in the table in my database. 我的数据库表中分别有一个“ DateTime列。 When i click the Edit in the table, the Date and Time should display the values by params . 当我单击表中的“编辑”时,“ DateTime应按params显示值。 The User can change the Date and the Time and update the form . 用户可以更改DateTime并更新form

I tried the following: 我尝试了以下方法:

<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>

It's not display the values correctly and it doesn't change to next record. 它不能正确显示值,也不会更改为下一条记录。 It display to select the value. 显示选择值。 Do I need to convert the date here? 我需要在这里转换日期吗? Because, In the Database, its just the value like 2013/05/13 and in the field its like 20 December 2013 因为,在数据库中,它的值就像2013/05/13而在字段中的值就像2013/05/13 20 December 2013

Time field is not working. Time字段不起作用。 Please suggest me how to get solve this issue. 请建议我如何解决此问题。

Thanks 谢谢

Don't use constants as fields for your model. 不要将常量用作模型的字段。 Any variable starting with a capital letter will be treated like a constant, and constants are meant not to change. 以大写字母开头的任何变量都将被视为常量,并且常量不可更改。 Ruby will give you a warning: already initialized constant when trying to change a constant's value, so that might be the reason you can't change the time and date. Ruby会warning: already initialized constantwarning: already initialized constant在尝试更改常量值时warning: already initialized constant ,因此这可能是您无法更改时间和日期的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM