,我有以下的Rails 4.2
应用的机型列表:的Rails 4.2的has_many通过就地编辑嵌套形式xeditable
- 用户
- 公司
- 市场
的关联看起来如下:
User.rb
class User < ActiveRecord::Base
end
Company.rb
class Company < ActiveRecord::Base
has_many :company_marketplaces
has_many :marketplaces, through: :company_marketplaces
accepts_nested_attributes_for :marketplaces, update_only: true
end
Marketplace.rb
class Marketplace < ActiveRecord::Base
has_many :company_marketplaces
has_many :companies, through: :company_marketplaces
end
我想建立一个形式允许添加/删除交易市场到公司借助就地编辑库x-editable
。我能够允许从现有列表中添加新市场,但由于没有提交数据,因此它在删除时失败。
这是视图的相关部分:
index.html.slim
td
= link_to company.marketplaces.join(", "), "", data: { :"name" => "marketplaces_attributes" , :"xeditable" => "true", :"url" => admin_agents_company_path(company), :"pk" => company.id, :"model" => "company", :"type" => "checklist", :"placement" => "right", :"value" => company.marketplaces.join(", "), :"source" => "/marketplaces" }, class: "editable editable-click"
而且companies_controller.rb#update
方法如下所示:
companies_controller.rb
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
我能找到的大部分资源都不会在现场进行编辑或使用fields_for
与nested_forms
一起使用。
是否有处理加/的形式除去has_many:
through:
相关联的对象,而不依赖于fields_for
溶液?
感谢