Forum: Ruby on Rails HOW I: Wrap content sections using blocks and then nest them

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.
blinking bear (Guest)
on 2007-07-04 21:47
(Received via mailing list)
This is the type of code that I'm excited when it works but hopefully
get some suggestions on how to do it better.  Last time, the code was a
to "ferocious" and I was missing out on a built in feature to rails that
didn't know about.

This one is a bit more complex... to factor out all the markup for
sections of the site I have a bunch of view helpers (thanks to Ryan
Bates: that are setup to take blocks.  Most
my views start off like this:

<% content_for :left do %>
    <% conversations_area do %>
       <!-- main content here -->
    <% end %>
<% end %>

This makes is tremendously easy to DRY up repeated code that doesn't
warrant its own layout bit is still fairly consistent.

To complicate this, however, we have different sections of the site that
scoped to a specifc group.  For example, a group could have its own
conversations area.  Using RESTful routes I'm reusing all the same
controllers and views for both.  Now the problem is, if I'm at the group
level I need to use the group's view helper.  Using lambdas and blocks
is pretty easy:

<% content_for :left do %>

    <!-- Define the content to pass to the view helper -->
    <% content = lambda do %>
        <!-- main content here -->
    <% end %>

    <!-- Determine which view helper to pass the block to -->
    <% if @group %>
        <% groups_area(@group) { } %>
    <% else %>
        <% conversations_area(@forum,@group) { } %>
    <% end %>

<% end %>

So far this is working great.  Any ideas on how to improve it?  Bonus

 Why don't here documents work in the helper files?

This topic is locked and can not be replied to.