I have in form this code line <%= f.collection_select :owner_ids, Owner.order(:id), :id, :name, {}, {multiple: true} %> that returns the list of owners in the massmedium form, but I need in this field also to include the companies too, so I could have in the same list the companies too, cause a massmedia chanel could be owned by a person or by a company.
Company.rb
class Company < ActiveRecord::Base
has_many :ownerships
has_many :massmedia, through: :ownerships
has_many :owners, through: :ownerships
end
Owner.rb
class Owner < ActiveRecord::Base
has_many :ownerships
has_many :massmedia, through: :ownerships
has_many :companies, through: :ownerships
end
Massmedium.rb
class Massmedium < ActiveRecord::Base
belongs_to :category
has_many :ownerships
has_many :owners, through: :ownerships
has_many :companies, through: :ownerships
end
u have to define
owners=(values)method in your model, which will parse values like [“Company,1″,”Owner,2”]