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
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. On 11/19/05, Toby Boudreaux <rails-lb8SQxIZKShBDgjK7y7TUQ@public.gmane.org> wrote:> 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 > > > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
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. On Nov 19, 2005, at 11:52 AM, Cuong Tran wrote:> 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. > > > On 11/19/05, Toby Boudreaux <rails-lb8SQxIZKShBDgjK7y7TUQ@public.gmane.org> wrote: >> 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 >> >> >> >> >> >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails