创建“主布局”在 Rails 中查看?
好吧,我有一个小项目,其中有两个不同的脚手架。在布局目录中有两个不同的layout.html.erb 文件。
我的问题是如何将其压缩为两个脚手架视图共享的一个主布局文件。
基本上我这样做的目的是这样我只需将导航栏和标题以及其他类似的东西都放在一个地方。
Ok so I have a small project with two different scaffoldings I've made.In the layouts directory therefor there is two different layout.html.erb files.
My question is how to condense this into just one main layout file that the two scaffolded views share.
Basically my purpose for doing this is so that I only have to have my navigation bar and header and other such things all in one place.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您将布局文件命名为application.html.erb,那么它将是默认布局文件。如果您指定与控制器同名的布局文件,则会覆盖默认布局。
来自 Rails 指南:
来源: http://guides.rails.info/layouts_and_rendering.html
编辑:
我应该添加您可以在应用程序控制器中指定任何布局作为默认布局:
这将覆盖 Rails 自动执行的名称匹配。
我希望这有帮助!
if you name the layout file application.html.erb, then it will be the default layout file. If you specify a layout file by the same name of your controller, that will override the default layout.
From Rails Guides:
source: http://guides.rails.info/layouts_and_rendering.html
EDIT:
I should add that you can specify any layout to be your default in the Application Controller:
And that will override name matching that rails does automatically.
I hope this helps!
您可以在布局目录中有一个
application.html.erb
,该目录将由所有视图共享You can have an
application.html.erb
in your layouts directory that will be shared by all of the views