[英]how to get date_field value when error message show in rails?
I want to show the date value in the date_field
when the post page, with errors, is rendered.我想在呈现有错误的帖子页面时在
date_field
显示日期值。
I've tried:我试过了:
<%= f.date_field :start_at_date,:class=>"form-control fdate"
,value: Date.current.strftime('%Y-%m-%d')%>
Which results in:结果是:
Try this code:试试这个代码:
<%= f.date_field :start_at_date,:class=>"form-control fdate",
value: model.errors.any? ? (Date.today):() %>
Replace "model" with your model name.用您的型号名称替换“型号”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.