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. -- Posted via http://www.ruby-forum.com/.
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 Whittaker wrote:> 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.Charlie Bowman http://www.recentrambles.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060324/2355cfb2/attachment.html
James Whittaker
2006-Mar-24 13:04 UTC
[Rails] Re: Changing sidebar in layout per controller
Charlie Bowman 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 Whittaker 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 Bowman > http://www.recentrambles.comThanks, I have just started doing just that after sitting down, having a cup of coffee and thinking about it. :-) -- Posted via http://www.ruby-forum.com/.
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 Whittaker wrote:>Charlie Bowman 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 Whittaker 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 Bowman >> http://www.recentrambles.com > >Thanks, I have just started doing just that after sitting down, having a >cup of coffee and thinking about it. :-) > > >-- >Posted via http://www.ruby-forum.com/. >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/railsMikkel Bruun www.strongside.dk - Football Portal(DK) nflfeed.helenius.org - Football News(DK) ting.minline.dk - Buy Old Stuff!(DK) -- Posted with http://DevLists.com. Sign up and save your time!