簡體   English   中英

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

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

我的數據庫表中分別有一個“ DateTime列。 當我單擊表中的“編輯”時,“ DateTime應按params顯示值。 用戶可以更改DateTime並更新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 constantwarning: already initialized constant在嘗試更改常量值時warning: already initialized constant ,因此這可能是您無法更改時間和日期的原因。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM