我有教堂,但是教堂在开张时有一个外国的桌子时间表。
churches_list.each do |name, street, city, zip, country, description|
church = Church.new(name: name,
street: street,
city: city,
zip: zip,
country: country,
description: description)
Schedule.create!(start_date: Date.today+7,
start_hour: t,
end_hour: t+8,
church_id: church.id,
schedule_type: "oneDay")
church.save但当我运行种子时,它只说明:“教堂至少需要一个时间表”。
所以我想我的church.schedules由于某些原因没有正确连接。
发布于 2016-09-11 20:46:01
从Schedule.create中删除ID并将创建的时间表保存到变量(ex时间表),然后执行以下操作
church.schedules = [schedule]在church.save修复该问题之前。我猜是让ActiveRecord将两者链接在一起,而不是在创建调度时强制使用ID来解决这个问题。
https://stackoverflow.com/questions/39435442
复制相似问题