Can't render layout in rails 3

試著忘記壹切 提交于 2019-12-25 01:26:01

问题


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.

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.


回答1:


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:


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.

You can read more about it here:

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



来源:https://stackoverflow.com/questions/6605716/cant-render-layout-in-rails-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!