【发布时间】:2014-12-24 17:50:08
【问题描述】:
我的印象是,如果您的 layouts 目录中有名为 application.html.erb 的文件,则此布局将自动应用于所有视图,而无需显式引用它。 情况似乎并非如此。
我有一个“家庭”控制器,它有一个“索引”方法:
class HomeController < ActionController::Base
def index
end
end
以及相关的home.html.erb查看页面:
<h2>Welcome!</h2>
<div>Stay tuned for basic functions to start arriving on this site.</div>
<div>The site will not look very stylish until one of the bounties gets done about writing the Style guide.</div>
最后是位于布局中的 application.html.erb 文件:
<!DOCTYPE html>
<html>
<head>
<title>App Title</title>
<%= stylesheet_link_tag "application", media: "all" %>
</head>
<body>
<div class="navbar">
<div class="navbar-inner">
<a href="/categories/index">Categories</a>
</div>
</div>
<%= yield %>
<div class="footer">Michael</div>
</body>
</html>
在我像这样在我的家庭控制器中添加对布局的显式引用之前,上面的文件被忽略了:
class HomeController < ActionController::Base
layout 'application'
def index
end
end
什么给了?我不想命名我在每个控制器中使用的布局。这就是在应用程序级别拥有它的意义所在。
【问题讨论】:
标签: css ruby-on-rails