无法以嵌套形式更新子元素

时间:2014-10-16 07:05:09

标签: ruby-on-rails ruby-on-rails-3.2 nested-forms

无法更新2级和3级嵌套表单属性。我可以更新1级属性,但不知道为什么它没有更新。

下面是我的代码

  def update
    @buyer.update_attributes(params[:buyer])
    if params[:id].to_i != 0 
      redirect_to wizard_path(:buyer_posting_params)
    else
      render_wizard @buyer
    end
  end

以下是我的参数

  

“买方”=> { “buyer_forms_attributes”=> { “0”=> { “buyer_posting_params_attributes”=> { “0”=> { “ID”=> “中13”,   “_destroy”=>“false”,“param_name”=>“11”,“param_type”=>“动态”,   “param_value”=>“”,“question_id”=>“17”},“1”=> {“id”=>“14”,   “_destroy”=>“false”,“param_name”=>“22”,“param_type”=>“动态”,   “param_value”=>“”,“question_id”=>“2”},“2”=> {“id”=>“17”,   “_destroy”=>“false”,“param_name”=>“33”,“param_type”=>“静态”,   “param_value”=>“test”,“question_id”=>“”}},“id”=>“4”},   “1”=> { “buyer_posting_params_attributes”=> { “1413443012516”=> { “_破坏”=> “中假” 时,   “param_name”=>“22”,“param_type”=>“dynamic”,“param_value”=>“”,   “question_id”=>“24”}},“id”=>“44”}}}

我正在使用Rails 3.2

关系如:

One Buyer HasMany BuyerForms
One BuyerForm HasMany BuyerPostingParams

请帮助我。

先谢谢

1 个答案:

答案 0 :(得分:0)

你接受嵌套属性吗?如果没有,这可能会对您有所帮助:

http://apidock.com/rails/ActiveRecord/NestedAttributes/ClassMethods/accepts_nested_attributes_for

# buyer.rb
accepts_nested_attributes_for :buyer_forms

# buyer_form.rb
accepts_nested_attributes_for :buyer_posting_params
相关问题