Rails / application.html.erb没有加载

5
我创建了一个Ruby应用程序,但应用程序的application.html.erb从未被加载(查看webrick输出时,我从未得到“Rendered CLASS/index.html.erb within layouts/application”,而是“Rendered CLASS/index.html.erb”)。
CLASS.html.erb也从未被加载。
只有在控制器中明确指定“render:file => 'layouts/application'”时,才会加载application.html.erb。
有人可以帮忙吗?
非常感谢!
Sebastien
2个回答

14

确保你的控制器继承自ApplicationController。

class YourController < ApplicationController
  ...
end

0

在你的ApplicationController中添加

layout :application

现在,您所有的控制器都使用类似于默认布局的应用程序。


应用控制器 < ActionController::Base protect_from_forgery 布局: 应用 - Sebastien
在另一个应用程序中,ApplicationController 看起来像这样: - Sebastien
应用程序控制器类 < ActionController::Base 保护免受伪造攻击。 - Sebastien
渲染时会考虑application.html.erb。 - Sebastien
这是不需要的,因为application.html.erb是默认的,除非你特别覆盖它。 - superluminary

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接