0
我有一個包含動態添加的產品(編號,數量)的訂單表格 <%= form_for(order)do | f | %>導軌:將多個對象列入白名單
<div class="field">
<%= f.label :note %>
<%= f.text_field :note %>
</div>
<div class="field">
<% Product.all.collect {|x| [x.name, x.id]}.each do |c| -%>
<%= label_tag(name=c.first) %>
<%= number_field_tag('products[][:qty]','',min:1) %>
<%= hidden_field_tag('products[][:id]',c.last) %>
<% end %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
和接收PARAMS如下:
{"order"=>{"note"=>"mm","user_id"=>"mm"}, "products"=>[{":qty"=>"2",":id"=>"1"}, {":qty"=>"2", ":id"=>"2"}]}
如何使這些參數 我試過,但沒有奏效:
params.require(:order).permit(:note)
params.permit(:products => [])