0

I have a Company and a Product model with has_and_belongs_to_many relationship.

# app/models/company.rb

class Company < ApplicationRecord
  has_and_belongs_to_many :products
end


# app/models/product.rb

class Product < ApplicationRecord
  has_and_belongs_to_many :companies
end

I want to make a company edit form with checkboxes for products and also have an option to add new products.

enter image description here

Six products listed above are default products for all companies.

Products added with other field will only be shown to the company who added them, like the following.

enter image description here

The problem: I can't add other company specific products with my current HABTM association, I want to know the rails way to achieve this. Please help!

Ammar Shah
  • 131
  • 2
  • 10

1 Answers1

0

Adding dynamic fields to form with HABTM associations. I found this article helpful. [http://railscasts.com/episodes/196-nested-model-form-part-1][1]

Hope your looking for the same

Dinesh Pallapa
  • 1,172
  • 18
  • 20