无法在rails 3中渲染布局

时间:2021-01-22 20:42:40

I have an application which was written for rails 2. I'm upgrading to rails 3. Most of the functionality of my app works but it does not render any layout. I'm using default 'erb' engine.

我有一个为rails 2编写的应用程序。我正在升级到rails 3.我的应用程序的大多数功能都可以工作,但它不会呈现任何布局。我正在使用默认的'erb'引擎。

I've explicitly called a layout in my controller but it just does not render even the simplest layout

我已经在我的控制器中明确地调用了一个布局,但它甚至不能渲染最简单的布局

layout 'application'

It does not throw any error.

它不会抛出任何错误。

When I create a new project and try to render a layout in it, it works perfectly.

当我创建一个新项目并尝试在其中呈现布局时,它完美地工作。

2 个解决方案

#1


3  

You have to use

你必须使用

render :layout => 'application'

You can check it out here :

你可以在这里查看:

http://guides.rubyonrails.org/layouts_and_rendering.html

Hope this helps!

希望这可以帮助!

#2


10  

The reason that the default layout for the controller isn't being used is because the controller is not properly initialized. This happens when there is an included module in your controller hierarchy that has an 'initialize' method that doesn't call super. This stops the initialize chain and you end up with this sort of problem.

未使用控制器的默认布局的原因是控制器未正确初始化。当控制器层次结构中包含的模块具有不调用super的“initialize”方法时,会发生这种情况。这会停止初始化链,最终会出现这种问题。

You can read more about it here:

你可以在这里读更多关于它的内容:

http://www.spiffystores.com/blog/2013/01/04/problems-rendering-a-layout-in-rails3/

#1


3  

You have to use

你必须使用

render :layout => 'application'

You can check it out here :

你可以在这里查看:

http://guides.rubyonrails.org/layouts_and_rendering.html

Hope this helps!

希望这可以帮助!

#2


10  

The reason that the default layout for the controller isn't being used is because the controller is not properly initialized. This happens when there is an included module in your controller hierarchy that has an 'initialize' method that doesn't call super. This stops the initialize chain and you end up with this sort of problem.

未使用控制器的默认布局的原因是控制器未正确初始化。当控制器层次结构中包含的模块具有不调用super的“initialize”方法时,会发生这种情况。这会停止初始化链,最终会出现这种问题。

You can read more about it here:

你可以在这里读更多关于它的内容:

http://www.spiffystores.com/blog/2013/01/04/problems-rendering-a-layout-in-rails3/