Forum: Ruby on Rails Re: How to let the layout be more OO?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Bradley M. (Guest)
on 2006-03-17 08:01
(Received via mailing list)

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.
Daniel -. (Guest)
on 2006-03-18 11:52
(Received via mailing list)

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 :)

This topic is locked and can not be replied to.