Ruby on rails 轨道编号\字段\标记输入无效
我有这个嵌套表单:Ruby on rails 轨道编号\字段\标记输入无效,ruby-on-rails,Ruby On Rails,我有这个嵌套表单: <div class="nested-fields"> <div class="row"> <div class="col-sm-3"> <%= select_tag "ingredients", "", class: 'ingredients'%> </div> <div class="col-sm-3">
<div class="nested-fields">
<div class="row">
<div class="col-sm-3">
<%= select_tag "ingredients", "", class: 'ingredients'%>
</div>
<div class="col-sm-3">
<%= number_field_tag "quantity", id: "quantity"%>
</div>
<div class="col-sm-2">
<%= f.label :price, id: 'price' %>
</div>
<div class="col-sm-2">
<%= f.label :total_amount, id: "total_amount", readonly: true %>
</div>
<div class="col-sm-2">
<%= link_to_remove_association "Remove", f, class: "btn btn-sm btn-danger" %>
</div>
</div>
</div>
“数量”字段为十进制:
t.decimal :quantity, :decimal, :precision => 8, :scale => 2
但当我在控制台上收到的数量字段中输入值时:
指定的值“{:id=\u003E\“数量\”,
:input_html=\u003E{:value=\u003E\“1.00000000\”}}不是有效的
号码。该值必须与以下正则表达式匹配:
-(\d++\d+。\d++.\d+)([eE][-+]?\d+)
为什么会这样?我该怎么修理
数字\字段\标记(名称,值=nil,选项={})
您需要更正您的number\u field\u标签
,如下所示
<%= number_field_tag "quantity", nil, id: "quantity" %>
谢谢你的回答。该错误从控制台中消失,但总金额始终更新为0。如果我更改为“价格”,并且“总金额”不再更新,我只能输入值manually@Catmal尝试调试该函数。检查是否正在调用该函数。该问题与其他问题有关。修复了我要求解决的错误。我要接受这个答案
<%= number_field_tag "quantity", nil, id: "quantity" %>
<%= f.text_field :price, id: 'price' %>
<%= f.text_field :total_amount, id: "total_amount", readonly: true %>