I have an application with a global application layout file application.html.haml. I then have multiple "controller stacks": for our main site, our admin portal, and our business site. For each of these, controllers are within a module and all inherit from the same BaseController. Each stack has it's own layout file. Within the stack, some controllers have layout files as well.

I would like all views (unless otherwise specified) to render inside multiple levels of nested layouts : application, "stack", "controller".

For example, for the Site::BlogController#show action, I'd like rails to render:

I am having difficulty understanding how to insert /layouts/site.html.haml into the stack. It appears as though automatically, rails will render the action inside the controller layout inside the application layout, however, I can't see how to "insert" layouts into the render stack.

Thanks for this, this was exactly what we were looking for! We also found out that you can do this with just using capture(&block), and this answer will work with ERB as well, because HAML aliases capture_haml to capture
– valscionJan 8 '14 at 13:49

Unfortunately, this method is much harder to generalize to larger nesting structures and requires a decent about of custom code. I was trying to avoid a solution like this.
– jesse reissJun 30 '11 at 18:43

Also using this method, but I find the 3 lines it takes up if you need it on a per action base frustrating, any ideaS?
– RubytasticFeb 14 '12 at 22:41

rescue nil here is very very bad: any error happening in the rendering of that file and you'll be oblivious. None of your users might be able to access the main page of your site and you wound't have idea. Just stop using rescue nil
– ecoologicJul 26 '16 at 7:51