如何从多个控制器调用视图?
我有多个控制器有自己的视图(Index.html)。现在,我想创建另一个控制器(说“欢迎”),并且我想将所有其他控制器的视图包含到“欢迎”的视图中,以便所有视图都在单个页面上可用,并且每当我创建欢迎页面时都会自动更新更改任何控制器的任何单独索引页。
I have multiple controllers having their own views (Index.html). Now, I want to create another controller (Say "Welcome") and I want to include views of all other controllers into the view of "Welcome", so that all the views are available on single page and welcome page gets updated automatically whenever I change any individual index page of any controller.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想在其他控制器视图中拥有一个控制器的视图,您应该将第一个视图渲染为文件
<%=render 'controller/action'%>
在这种情况下,您必须分配所有变量构建此视图所必需的(在操作内分配的所有变量)但是您将在控制器布局中渲染此视图,如果您有一些过滤器,则还必须将它们应用到新控制器If you whant to have view of one controller inside other controllers view you should render first view as a file
<%=render 'controller/action'%>
and in such case you must assign all variables that are neccessary for building this view(all variables that are assigned inside action) But you'll render this view inside your controllers layout and if you have some filters you also must apply them to the new controller