У меня в форме эта строка кода <%= f.collection_select :owner_ids, Owner.order(:id), :id, :name, {}, {multiple: true} %>
, которая возвращает список владельцев в форме массовой информации, но мне также нужно включить в это поле также компании, поэтому я мог бы иметь в тот же список компаний также, причиной, что массовое звено может принадлежать человеку или компании.f.collection_select from 2 tables in rails 3
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