小编A1a*_*aks的帖子

param'samples'的预期Hash(得到数组)

我一直在关注嵌套表单和复杂表单的Railscasts剧集.在单个表单中创建多个模型的过程中,我能够编辑,更新,删除和创建嵌套在Batch模型中的样本模型的记录.

我很长时间以来一直在试图解决这个问题但是无法找到合适的解决方案.

我的开发日志文件给我以下错误.

错误信息:

Status: 500 Internal Server Error
  expected Hash (got Array) for param `samples'
Run Code Online (Sandbox Code Playgroud)

在我的控制器中,我有这样的更新动作

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
Run Code Online (Sandbox Code Playgroud)

我的观点是这样的:

<%= form_for @batch do |f| %>
......
<%= f.fields_for :samples do |s_form| %>
.... s_form things
<% …
Run Code Online (Sandbox Code Playgroud)

edit nested-forms multiple-models ruby-on-rails-2

9
推荐指数
2
解决办法
8040
查看次数