当我尝试保存多个对象时,出现下一个错误:
undefined method `stringify_keys' for #<Array...>
关于如何处理它的任何想法?我的输入:
控制器:
def create
@course = Course.find(params[:course_id])
@students = @course.users
@students.each do
@grade = @course.grades.build(params[:grade])
end
@grade.each { |a| a.save }
end
_form.html.erb:
<%= form_for ([@course, @grade]) do |f| %>
....
<% @students.each do |a| %>
<tr>
<td><%= a.last_name %><%= a.first_name %>
<%= f.hidden_field :student_id, :value => a.id, :index => @grade.id %></td>
<td><%= f.text_field :grade_evaluation, :index => @grade.id %></td>
<td><%= f.text_field :comment, :index => @grade.id %></td>
</tr>
....
这给了我下一个参数哈希等级:
{....
"grade"=>[
{"student_id"=>"1",
"grade_evaluation"=>"5",
"comment"=>"you are an idiot" },
{"student_id"=>"4",
"grade_evaluation"=>"5",
"comment"=>"you too" }],
"commit"=>"Create",
"course_id"=>"3"}