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.
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.
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!