nested_form 中点击添加后怎么为 text_field 添加 id
view
erb
<%=f.fields_for :specifications do |spe|%> <div class="col-sm-12"> <label class="control-label col-sm-2 col-sm-offset-1">库存数:</label> <% sizes.each do |size| %> <div class="col-sm-1"> <%= text_field_tag "inventories#{ spe.object.id }[]", "",class: 'form-control' %> </div> <% end %> </div> <% end %> <div class="form-group"> <%= f.link_to_add '+添加一个规格', :specifications, class: 'col-sm-12' %> </div>
我想实现的是,在点击添加的时候在text_field_tag上添加一个ID或者类似用来辨识的标识,然后我在后台就可以直接用那个辨识符进行更新操作。
现在能获取到的参数,如下是两个以存在的specification,另外新建的三个合并在一起了。
shell
"inventories19"=>["", "", "", "", "", "", ""], "inventories20"=>["", "", "", "", "", "", ""], "inventories"=>["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""]
希望有人能帮我解惑一下。
sanmao
11 years, 10 months ago