我一直在跟踪嵌套形式和复杂形式的Railscasts集。在以单个表单创建多个模型的过程中,我能够编辑,更新,删除和创建嵌套在Batch模型中的示例模型的记录。
我很长时间以来一直不知所措,也尝试过四处搜寻,但找不到解决此问题的正确方法。
我的开发日志文件给我以下错误。
错误消息:
Status: 500 Internal Server Error
expected Hash (got Array) for param `samples'
在我的控制器中,我有这样的更新操作
def update
@batch = Batch.find(params[:id])
respond_to do |format|
if @batch.update_attributes(params[:batch])
flash[:notice] = 'Successfully updated Batch.'
format.html { redirect_to(@batch) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @batch.errors, :status => :unprocessable_entity }
end
end
end
我的看法是这样的:
<%= form_for @batch do |f| %>
......
<%= f.fields_for :samples do |s_form| %>
.... s_form things
<% end %>
<% end %>
我的模型包含相同的内容:
has_many :samples, :dependent => :destroy
accepts_nested_attributes_for :samples, :reject_if => lambda { |a| a[:content].blank? }, :allow_destroy => true
感谢所有建议。
对于遇到相同问题的其他人:
我有同样的问题,只是解决了。
我也收到此错误Invalid request parameters: expected Hash (got Array) for param 'cell'
。