我有一个有自己风格的主页(放在 application.css
中)但是网站的其余部分将完全不同。
然而,Rails 似乎使用“父”文件 application.html.erb
并且我们基本上可以使用 yield
来包含其他 .html。 erb
页面。
但是,它对我的应用程序不可行,因为正如我所说,主页的结构与我的网络应用程序的其余部分完全不同,我不能使用通用的 application.html.erb
文件。
这种情况有什么解决办法?
最佳答案
您可以在范围内或为特定操作指定布局 Controller 。
布局文件需要放在layouts
文件夹中。
要在 Controller 范围内指定布局文件,您可以这样做
class BlogController < ActionController::Base
layout "unique_blog_layout"
def index
end
...
end
为单个 View 设置它
class BlogController < ActionController::Base
def index
render layout: "unique_blog_layout"
end
...
end
关于html - 我的 Rails 应用程序的不同应用程序布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45131041/