在不耦合的情况下将多个视图合并为一个视图?
假设我有:
对象 A、B、C,每个对象都有相应的模型、视图和控制器
您如何将它们全部加载到一个视图(站点索引)中?您可以使用每个模型索引的一部分,但是不会调用该特定控制器的方法,因此您必须添加该视图的方法。还有其他建议吗?谢谢!
Let's say I have:
object A, B, C each with corresponding models, views, and controllers
How would you load them all into one view (site index)? You could use a partial of each model's index, but then methods of that particular controller don't get called so you would have to add that view's methods. Any other suggestions? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你所描述的就是你所能做的一切。
但是,无论您从何处访问该模型,仍然可以访问每个模型的方法。除非您正在谈论辅助方法。在这种情况下,您需要将
helper :a, :b, :c
添加到站点索引控制器,以便可以从站点索引呈现的视图和部分中获取与每个模型关联的帮助器方法控制器。What you've described is about all you can do.
However, methods of each model are still accessible no matter where you access that model from. Unless you're talking about helper methods. In which case you'll need add
helper :a, :b, :c
to the site index controller, so that the helper methods associated with each model are available from views and partials rendered by the site index controller.