问题
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