Forum: Ruby on Rails Partial Confusion

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.
rails (Guest)
on 2005-11-19 18:43
(Received via mailing list)
I left my Rails book at work and am having a hard time googling this
one, though it's likely easy.

I have a smallish site running on a single master layout. The master
layout has a sidebar which has, until now been the same.

I'd like to render a particular partial in the sidebar for certain

In some cases, there won't be a partial for the sidebar.

What is the most elegant way of handling this?

I'm sure there is something simple built in, but as I said, my book
is at the office.

cuong.tran (Guest)
on 2005-11-19 18:55
(Received via mailing list)
This is what I do to have different sidebar per controller:

  def render_sidebar
    if @sidebar_content
        render :partial => 'sidebar'
Then just call render_side inside your layout.  You can extend this to
include sidebar per action.
rails (Guest)
on 2005-11-20 08:01
(Received via mailing list)
Ah, I see. Seems like a waste, though, doing filesystem lookups on
every page view. I think I'll just write something that uses a hash
of known possibilities, or look at restructuring my view code. Thanks.
This topic is locked and can not be replied to.