Rails正在给我这个错误主题(#70287575068140)预期,得到字符串(#70287576459120),但我的参数是:
Parameters:
{"utf8"=>"✓",
"_method"=>"patch",
"authenticity_token"=>"rISZVyQZgcLCGP1y7F4qg7xmW1miuaJvwUe5gu59/MqjjSWem/3JzCei5EPuZSSVdZyqO8bq0eRk0w9zCo0mDA==",
"student"=>{"name"=>"Eduardo Pedroso",
"rg"=>"39468291-0",
"phone"=>"981713271",
"address"=>"Rua dr Camilo marques",
"birthday"=>"2015-06-08",
"scholarity"=>"Superior",
"responsible_id"=>"1",
"subjects"=>["#<Subject:0x007fda346828e0>",
"#<Subject:0x007fda34682660>"]},
"commit"=>"Edit student",
"id"=>"1"}
发送主题参数的复选框
<% Subject.all.each do |subject| %>
<%= check_box_tag :subjects_id, subject, @student.subjects.include?(subject), :name => 'student[subjects][]' -%>
<%= label_tag :subjects, subject.name %>
<% end %>
答案 0 :(得分:0)
尝试更改
<%= check_box_tag :subjects_id, subject, @student.subjects.include?(subject), :name => 'student[subjects][]' -%>
到
<%= check_box_tag :subjects_id, subject, @student.subjects.include?(subject), :name => 'student[subjects_id][]' -%>
答案 1 :(得分:0)
您最好检查check_box_tag helper
周围的定义它是这样的:
check_box_tag(name,value =“1”,checked = false,options = {})
因此,与您的使用情况相比,您已将name
属性分配了两次,并将其指定为对象subject
的值。
我认为您打算将subject.id
分配为值,因此您可以将check_box_tag
调用替换为:
<%= check_box_tag 'student[subjects][]', subject.id, @student.subjects.include?(subject) -%>