从表单提交的内容与 Rails 服务器识别为参数的内容之间似乎存在不一致...除非我做错了什么/不了解参数数组的工作原理...这是可能的。
这就是我制作复选框的方式:
current_event.competitions.map { |competition|
content_tag(:div, class: "checkbox"){
check_box_tag("attendance[competition_ids]", competition.id, @attendance.competitions.include?(competition.id)) +
label("attendance[competition_ids]", competition.id, label_with_price(competition))
}
}.join.html_safe
这就是 chrome web 检查器所说的被发送到服务器的内容:
attendance[competition_ids]:1
attendance[competition_ids]:2
attendance[competition_ids]:3
但是 Rails 抛出了这个错误:
ActiveModel::ForbiddenAttributesError
这是我的参数辅助方法是我的控制器
params[:attendance].permit(:package, :level, competition_ids: [])
由 rails 标识的参数: 参数:
{"utf8"=>"✓",
"authenticity_token"=>"qZ1gtwZoXgs9P0HdberzrsMO7L1NftmB8yGso0WquOY=",
"attendance"=>{"competition_ids"=>"3"},
"discounts"=>[""],
"commit"=>"Register"}
我的参数不应该看起来更像:
"attendance"=>{"competition_ids"=>["1","2","3"]}
?