【问题标题】:Unable to Update child element in nested form无法以嵌套形式更新子元素
【发布时间】:2014-10-16 07:05:08
【问题描述】:

无法更新 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"=>{"buyer_forms_attributes"=>{"0"=>{"buyer_posting_params_attributes"=>{"0"=>{"id"=>"13", "_destroy"=>"false", "param_name"=>"11", "param_type"=>"dynamic", "param_value"=>"", "question_id"=>"17"}, "1"=>​​{"id"=>"14", "_destroy"=>"false", "param_name"=>"22", "param_type"=>"dynamic", "param_value"=>"", "question_id"=>"2"}, "2"=>{"id"=>"17", "_destroy"=>"false", "param_name"=>"33", "param_type"=>"static", "param_value"=>"test", "question_id"=>""}}, "id"=>"4"}, "1"=>​​{"buyer_posting_params_attributes"=>{"1413443012516"=>{"_destroy"=>"false", "param_name"=>"22", "param_type"=>"动态", "param_value"=>"", "question_id"=>"24"}}, "id"=>"44"}}}

我正在使用 Rails 3.2

关系如下:

One Buyer HasMany BuyerForms
One BuyerForm HasMany BuyerPostingParams

请帮帮我。

提前致谢

【问题讨论】:

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


    【解决方案1】:

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

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-25
      • 2023-04-01
      • 2023-02-21
      • 2022-01-22
      • 1970-01-01
      相关资源
      最近更新 更多