ruby-on-rails - Rails:如何根据 foriegn_key 自动循环创建项目
问题描述
我正在尝试学习比我一直在做的更复杂的事情。所以我开始了一个个人项目并立即卡住了。
我的模型父(Person - has_many)子(Checklist belongs_to)运行良好。
我有一个模型测试(has_many)并将其附加到问题(belongs_to),test_id 都运行良好。两种标准设置。
当在一个人(/person/1/checklists/new)上时,我想通过它找到具有相同 test_id 循环的所有问题,并将其附加到一个清单(belongs_to question)和问题(has_many checklists)。
def create
person = Person.find(params[:person_id])
@checklist = person.checklists.new(ckecklist_params)
# Above Works Fine (no idea what to do to loop through below)
@question = Person.where(questions.test_id => person.test_id )
@question.each do |test_builder|
test_builder.create(?????)
end
end
我可以发布额外的细节和代码,只是试图超越基础。即使是指向正确方向的链接也会很棒。
解决方案
推荐阅读
- cognos - 要传递给 SQL 的 Cognos Static 提示值
- javascript - 在链式承诺的每一步评估价值并打破承诺
- python - 从 csv 文件中取出一列并将其放入 python 中的列表中
- r - 使用 if 语句将两个数据帧连接在一起
- bloomberg - from xbbg import blp 适用于股票,但不适用于债券
- bokeh - 从散景控件中删除额外的 Divs 和 css
- node.js - Mongoose exec() 没有正确等待
- javascript - 无法将样式应用于 Reactjs 中的样式化组件元素
- javascript - 将 mapDispatchToProps 定义为函数时,Redux 操作不再起作用
- oracle - ORA-600 [32695] [无法进行哈希聚合]