I am trying to update product_suppliers through a product form. The form displays all suppliers in the supplier table, but does not update the connection table. I donβt know where the error is. Index and display show the correct data, but editing does not update the connection table. Start walking around and around circles on it.
Update: Changing the form to below closed me. But do not update the connection table. However, the removal works as expected if I manually add rows to the connection table. They are displayed and can be deleted. Saving adds the new product_id to the string, not the supply_company_id value associated with it. I consider its problem with the attribute, but I do not see it.
application / models / product.rb
class Product < ActiveRecord::Base
app / models / supply_company.rb
class SupplyCompany < ActiveRecord::Base has_many :products, :through => :product_suppliers has_many :product_suppliers, :foreign_key => 'supply_company_id' end
app / models / product_supplier.rb
class ProductSupplier < ActiveRecord::Base belongs_to :product belongs_to :supply_company accepts_nested_attributes_for :product accepts_nested_attributes_for :supply_company end
/app/admin/product.rb
ActiveAdmin.register Product do # See permitted parameters documentation: # https:
product_suppliers_schema
create_table "product_suppliers", force: true do |t| t.integer "product_id" t.integer "supply_company_id" t.datetime "created_at" t.datetime "updated_at" end
Update: Changing the form to a lower level brought me closer. But do not update the connection table. However, the removal works as expected if I manually add rows to the connection table. They are displayed and can be deleted. Saving adds the new product_id to the string, not the supply_company_id value associated with it . I consider its problem with the attribute, but I do not see it.
f.inputs "Suppliers" do f.has_many :product_suppliers do |ff| ff.input :supply_company_id, as: :select, multiple: true, collection: SupplyCompany.all.map {|u| [u.company_name.to_s, u.id]} ff.input :_destroy, :as=>:boolean, :required => false, :label => 'Remove supplier' end end