Forum: Ruby on Rails Partial Confusion

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.
70d14478017f13972bb6d82a5dcf161f?d=identicon&s=25 rails (Guest)
on 2005-11-19 17:43
(Received via mailing list)
Heya.
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
controller/actions.

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.

Thanks,
toby
Accad816054fc1b2fa7dae2a2fce5266?d=identicon&s=25 cuong.tran (Guest)
on 2005-11-19 17:55
(Received via mailing list)
This is what I do to have different sidebar per controller:

application_helper.rb
--
  def render_sidebar
    if @sidebar_content
      @sidebar_content
    elsif
FileTest.exist?("#{controller.template_root}/#{controller.controller_name}/_sidebar.rhtml")
        render :partial => 'sidebar'
    end
  end
--
Then just call render_side inside your layout.  You can extend this to
include sidebar per action.
70d14478017f13972bb6d82a5dcf161f?d=identicon&s=25 rails (Guest)
on 2005-11-20 07: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.