我想通过simple_form,
批量更新记录代码如下:
= simple_form_for url: batch_update_admin_tuitions_path, method: 'put' do |f|
table.table
thead
tr
th.text-center
th.text-center column1
th.text-center column2
th.text-center column3
tbody.text-center
- @tuitions.each do |tuition|
tr
td = f.input_field "user_ids[]", as: :boolean, value: tuition.user_id
td = @users_hash[tuition.user_id].name
td = tuition.num
td = tuition.sum_amount
= f.submit :Submit, class: 'btn btn-success'
但它不起作用, ```
参数:
{"utf8"=>"✓",
"authenticity_token"=>"FDpxyq9LE8UjxBjIm4lstj29N86Xlja+czWZXDdMcnehgBzmh0zz7aE5ZKqGWCWtX/h+iRwnTE048IPPodG10w==", "/admin/tuitions/batch_update"=>{"user_ids"=>[]}, "commit"=>"Submit"}
我发现了一个问题:user_ids为空。如何将user_ids传递给params?谁有好主意?先谢谢!
答案 0 :(得分:0)
从SimpleForm文档中,提供了一些帮助程序:
form_for @tuition do |f|
f.collection_check_boxes :user_ids, User.all, :id, :name
end
if you have an association,您可以使用as: :check_boxes
:
<%= simple_form_for @tuition do |f| %>
<%= f.association :users, as: :check_boxes %>
<%= f.button :submit %>
<% end %>
更一般地说,我认为SimpleForm使用f.input
而不是f.input_field
,因此您的代码应为:
td = f.input "user_ids[]", as: :boolean, value: tuition.user_id