Re: How to let the layout be more OO?


I encountered the same issue. I’m sure there are better ways to do
this, and perhaps some even “blessed” ways, but here is what I did.

In my application controller, I added the following:

before_filter :render_sidebars


def render_sidebars
@left_sidebar_for_layout = render_to_string(:partial =>
@right_sidebar_for_layout = render_to_string(:partial =>

Then, in my application layout, I use these new content variables the
same as I would for @content_for_layout.

It’s not pretty, but it works.

Anyone got a better way?


Bradley M.


I am just about to launch into something similar. One thing that I have
been thinking of (but havn’t had time to try yet) is to use the

Using Techno-weenie’s acts_as_authenticated as a guide, the index page
contains the following

<%% content_for ‘poem’ do -%>

some text in here

<%%= simple_format @content_for_poem %>

I’m not sure why there is %% in there but it works.

What my thinking is that in your view you could include many of these
content_for ‘name’ functions
that would then be rendered in your layout.

The doc is available at

This is then available to your layouts as <%= @content_for_name %>

I hope this works… I’m going to be trying it soon :slight_smile:


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs