Ruby on Rails 中是否有某种母版页功能?
在过去七年左右的时间里,我一直是一名 .Net 开发人员,最近几年我一直在使用 ASP.Net。我现在在一些项目中使用 Ruby on Rails,我想知道 Ruby on Rails 中是否有某些功能可以让您执行母版页类型的操作?
基本上,我想要一种通过页眉和页脚等为网站提供一致的外观和感觉的方法,然后让每个页面将其内容放入其中。你如何做到这一点?
I've been a .Net developer for the past seven years or so, and been working with ASP.Net for the last couple of years. I'm now using Ruby on Rails for some projects, and I'm wanting to know if there is something in Ruby on Rails that lets you do master page type stuff?
Basically, I want a way to provide a consistent look and feel for the site with a header and footer and so on, and then just have each page put its content inside of that. How do you accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 app/layouts/application.(html.erb|html.haml) 的 Rails 项目中,这是 master 的布局或等效布局。
您还可以创建其他布局并指定每个操作使用的布局:
或者指定整个控制器的布局:
in your rails project in app/layouts/application.(html.erb|html.haml), this is the layout or equivalent for master.
You can also create other layouts and specify the layout to use for each action :
Or specify the layout for a whole controller :
您可以使用类似于 ASP.Net 中的母版页的布局,有多种方法可以将母版页分配给您的铁路应用程序:
submaster 位于 app/views/layouts/submaster.html.erb
main 位于 app/views/layouts/main.html.erb
如果当前用户是管理员用户,他们将获得管理布局,其他子主布局。
如果可能,请检查轨道中的产量标识。
You can use layout which is look like master page in ASP.Net, there are many way to assign master page to your rail application :
submaster is located at app/views/layouts/submaster.html.erb
main is located at app/views/layouts/main.html.erb
If current user is a admin user, they'll get a admin layout else submaster layout.
If possible, please check yield identifies in rails.