参数'samples的预期哈希值(got Array)

问题描述 投票:9回答:3

我一直在跟踪嵌套形式和复杂形式的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

感谢所有建议。

edit nested-forms ruby-on-rails-2 multiple-models
3个回答
16
投票

对于遇到相同问题的其他人:


4
投票

我有同样的问题,只是解决了。


0
投票

我也收到此错误Invalid request parameters: expected Hash (got Array) for param 'cell'

© www.soinside.com 2019 - 2024. All rights reserved.