Layouts Ignored in Rails Controllers
This is probably going to be another one of those three-second fixes, but I've really checked and re-checked all of my code this time. I'm trying to get a custom layout to display in a Rails app, but layout declaration in ApplicationController is not getting propagated to subclasses.This does not work, meaning I don't get my custom layout:
class ApplicationController < ActionController::Base
layout 'standard'
end
This does work, however:
class PhotosController < ApplicationController
layout 'standard'
end
My layout file is in view/layouts/standard.rhtml. I'm just following along in the O'Reilly Rails book on page 74. If I add a "hello world" method with render_text to ApplicationController, it is successfully inherited by PhotosController, so I know the class is being loaded. It just seems be ignoring layout.
Am I missing something obvious? It's not the end of the world if I have to put layout in multiple files, but I'd just like to understand what's going on. Nothing relevant in the log file and I tried Googling for various things, but all the pages I found suggest I'm doing it the right way.
I'm using Locomotive 2.0.8 with "Standard Rails Sept 2006".

Layouts Ignored in Rails Controllers
Posted Jan 8, 2007 — 10 comments below
Posted Jan 8, 2007 — 10 comments below
Tammer Saleh — Jan 09, 07 3113
Good luck.
Scott Stevenson — Jan 09, 07 3114
Scott Matthewman — Jan 09, 07 3115
Scott Matthewman — Jan 09, 07 3116
Chuck — Jan 09, 07 3117
According to the documentation, explicitly setting a layout will override any automatic layout choice for that class, but a parent class's layout will not override a child's layout.
If you want to explicitly extend a class's layout to all of its subclasses, you should be able to do that with the inherited method. The way Rails does it seems most flexible to me, though.
Matt Tavares — Jan 09, 07 3118
<%= yeild %>
Matt Tavares — Jan 09, 07 3119
add a <%= yeild %> tag to the <body> tag of your layout (sorry if you've already done this, but this is where my layouts screw up 50% of the time).
Mike — Jan 09, 07 3120
Tammer Saleh — Jan 09, 07 3170
BTW: My coworkers and I were really impressed with your blog design.
Richard McIntyre — Feb 28, 07 3664
it worked out that I had a parse error in my layout file and rather than show me the error in this file, rails just defaulted to the layout that scaffold set up for me.
If you delete the scaffold layout file as others have suggested it may help you.