Changing sidebar in layout per controller

I am currently using 2 layouts in my site. One is for the admin area. I
am trying to get content in my sidebar to change depending upon the
current controller.

Example:

Within admin I have a users controller and a articles controller. When
in the users view I want the sidebar to display options (like add user
delete user etc).

What is the best actionview way to do this. I don’t want loads of
differing layouts as there could be many different controllers in
future.

I could use render partial but then in each of the controllers actions I
would have a load of repeated html breaking the DRY rules.

I accomplished this exact same task by creating a method in my
application helper. This method would dynamically create my navbar
based on a context variable that I would set in each template. (<%
@context = ‘about’ %>). I would call my application helper method in my
layout and let it return my modified navbar. This solution works great
for me.

On Fri, 2006-03-24 at 12:20 +0100, James W. wrote:

What is the best actionview way to do this. I don’t want loads of
differing layouts as there could be many different controllers in
future.

I could use render partial but then in each of the controllers actions I
would have a load of repeated html breaking the DRY rules.

Charlie B.
http://www.recentrambles.com

Charlie B. wrote:

I accomplished this exact same task by creating a method in my
application helper. This method would dynamically create my navbar
based on a context variable that I would set in each template. (<%
@context = ‘about’ %>). I would call my application helper method in my
layout and let it return my modified navbar. This solution works great
for me.

On Fri, 2006-03-24 at 12:20 +0100, James W. wrote:

What is the best actionview way to do this. I don’t want loads of
differing layouts as there could be many different controllers in
future.

I could use render partial but then in each of the controllers actions I
would have a load of repeated html breaking the DRY rules.

Charlie B.
http://www.recentrambles.com

Thanks, I have just started doing just that after sitting down, having a
cup of coffee and thinking about it. :slight_smile:

I have a sidebar method in application.rb that renders the default
sidebar.
I can the override this method is whatever controllers that might need
it

In the layout i do a render_component calling sidebar on the current
controller.

I also pass the original action and the original id, these may be handy
when rendering some specific sidebar

On Friday, March 24, 2006, at 2:04 PM, James W. wrote:

Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

Mikkel B.

www.strongside.dk - Football Portal(DK)
nflfeed.helenius.org - Football News(DK)
ting.minline.dk - Buy Old Stuff!(DK)