Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 4 Rails 4.2有许多通过xeditable进行就地编辑的嵌套表单_Ruby On Rails 4_Form Submit_Frontend_Nested Forms_X Editable - Fatal编程技术网

Ruby on rails 4 Rails 4.2有许多通过xeditable进行就地编辑的嵌套表单

Ruby on rails 4 Rails 4.2有许多通过xeditable进行就地编辑的嵌套表单,ruby-on-rails-4,form-submit,frontend,nested-forms,x-editable,Ruby On Rails 4,Form Submit,Frontend,Nested Forms,X Editable,我在Rails 4.2应用程序中有以下型号列表: 使用者 公司 市场 这些关联如下所示: User.rb class User < ActiveRecord::Base end class Company < ActiveRecord::Base has_many :company_marketplaces has_many :marketplaces, through: :company_marketplaces accepts_nested_attribut

我在
Rails 4.2
应用程序中有以下型号列表:

  • 使用者
  • 公司
  • 市场
这些关联如下所示:

User.rb

class User < ActiveRecord::Base
end
class Company < ActiveRecord::Base

  has_many :company_marketplaces
  has_many :marketplaces, through: :company_marketplaces

  accepts_nested_attributes_for :marketplaces, update_only: true
end
def update
  respond_to do |format|
    if @company.update(company_params)
      format.html { redirect_to @company, notice: 'Company was successfully updated.' }
      format.json
      format.js
    else
      format.html { render :edit }
      format.json { render json: @company.errors, status: :unprocessable_entity }
      format.js
    end
  end
end
companys_controller.rb#update
方法如下所示:

公司\u controller.rb

class User < ActiveRecord::Base
end
class Company < ActiveRecord::Base

  has_many :company_marketplaces
  has_many :marketplaces, through: :company_marketplaces

  accepts_nested_attributes_for :marketplaces, update_only: true
end
def update
  respond_to do |format|
    if @company.update(company_params)
      format.html { redirect_to @company, notice: 'Company was successfully updated.' }
      format.json
      format.js
    else
      format.html { render :edit }
      format.json { render json: @company.errors, status: :unprocessable_entity }
      format.js
    end
  end
end
我能找到的大多数资源都不处理就地编辑或使用
字段来处理
嵌套表单

是否有一种解决方案可以处理添加/删除
的多个:
到:
表单中的关联对象,而不依赖
字段


谢谢

您可以在params中提供marketplaces\u属性

示例来自:

类成员2
member.posts.first.title#=>“Kari,很棒的Ruby文档浏览器!”
member.posts.second.title#=>“现代公民的平等主义假设”
阅读以上链接中的更多示例