0
我想在創建數組時將一個對象數組與另一個對象關聯,而不指定id。我很確定我以前見過這個,但是找不到它。將數組與軌道中的對象關聯起來。
class User < ActiveRecord::Base
has_many :companies
has_many :job_groups
end
class Job < ActiveRecord::Base
belongs_to :job_group
end
class JobGroup < ActiveRecord::Base
belongs_to :user
has_many :jobs
end
Company.rb
def self.user_links(user)
job_group = JobGroup.create(user_id: user.id)
user.companies.each do |c|
links = c.find_links
job_group << links
end
end
鏈接回來爲一組鏈接,我想它關聯到一個工作組。
我得到一個NoMethodError:未定義的方法`< <'的