我正在创建一个问卷应用程序,允许用户创建一个问卷。
一份问卷由两个不同的 Controller 组成:
- 问题
- 内容(允许问题之间的标题将它们分开)
然后我有一个“Questionnaire_Items” Controller ,它将问题和内容整合在一起。这包含 question_id 或 content_id 和订单值。
所以我需要我的 questionnaire_item View 来提取问题数据或内容数据(取决于是否存在 question_id 或 content_id)。
执行此操作的最佳方法是什么? 有没有更好的方法来实现我想要的目标?
感谢您的帮助。
最佳答案
我觉得你可能想的有点不对。看这里http://guides.rubyonrails.org/action_controller_overview.html#what-does-a-controller-do-questionmark ; Controller 接收请求并决定响应,因此您的 Controller 确定要呈现的 View , View 不决定从哪个 Controller “拉”。另外,问题和内容不是模型吗?
我能想到的最简单的方法是在您的 Controller 中构建一个问卷项目,然后呈现您的 View 。
关于ruby-on-rails - rails 上的 ruby : Multiple controllers in one view,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44197746/