[英]Rails if statement for date_field
我正在放屁。 我需要一條if語句,如果已選擇一個日期,則使用該選擇,否則請使用“今天的日期”(硬編碼)。 我不記得是應該在date_field所在的視圖中,還是需要在控制器或模型中。
表單代碼:
<div class="form-group">
<%= f.label :sinDate, "Down Since", class: "col-md-2 control-label" %>
<div class="col-md-4">
<%= f.date_field :sinDate, class: "form-control" %>
<p><small>This is optional, use if the down date was before today.</small></p>
</div>
</div>
嘗試跟隨
<%= f.date_field :sinDate, as: :date,
value: (f.object || Date.Today).try(:strftime,"%m/%d/%Y"),
class: 'form-control' %>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.