Datepicker正在选择日期,但它没有保存到我的数据库。尝试下面的代码中显示的几个选项,但它仍然无法正常工作。这段代码给我一个错误。如何正确格式化f.text_field?
<div class="form-group">
<label class="control-label col-sm-5" for="time_stop">Job Date:</label>
<div class="col-sm-7">
<%= f.text_field :jobdate, :id => @appointment.jobdate, "data-provide" => 'datepicker', @appointment.jobdate, class: "form-control" %>
</div>
<script>
$(function() {
$( "#jobdate" ).datepicker();
});
</script>
</div>
错误消息:
/home/ubuntu/workspace/agss/app/views/appointments/_form.html.erb:95: 语法错误,意外&#39;,&#39;,expecting =&gt; ... epicker&#39 ;, @ appointment.jobdate,class:&#34; form-control&#34; ); @ out ...... ... ^
答案 0 :(得分:1)
参数的顺序错误。它应该是
<%= f.text_field :jobdate, "data-provide" => 'datepicker', class: "form-control" %>
不
<%= f.text_field :jobdate, :id => @appointment.jobdate, "data-provide" => 'datepicker', @appointment.jobdate, class: "form-control" %>
请注意,您无法传递@appointment.jobdate
,因为该值已从与表单相关联的对象中获取。
注意f.
。这是一个表单构建器,而不是标准的text_field_tag
帮助程序。