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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
6f94c45fd92acbb3e21c328f6b35298a?d=identicon&s=25 Bradley Mazurek (Guest)
on 2006-03-17 07:01
(Received via mailing list)
Hi,

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

  private

  def render_sidebars
    @left_sidebar_for_layout = render_to_string(:partial =>
'shared/left_sidebar')
    @right_sidebar_for_layout = render_to_string(:partial =>
'shared/right_sidebar')
  end

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?

Thanks,
  Brad
--
Bradley Mazurek
9d1f5d2d9de70bd9a934f557dc95a406?d=identicon&s=25 Daniel ----- (liquid)
on 2006-03-18 10:52
(Received via mailing list)
Hi,

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
content_for
method.

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
http://api.rubyonrails.org/classes/ActionView/Help...

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

I hope this works..  I'm going to be trying it soon :)

Cheers
Dan
This topic is locked and can not be replied to.