On 12/2/05, Beau O''Hara <bohara-Ani+Op4kYNUXWzRTk0ed69BPR1lH4CV8@public.gmane.org> wrote:> I have a side navigation that i want to change based on the controller. > How would i test for this in .rhtml. for example lets say i have an > admin controller. > > Example > -------------------- > <% if @controller = admin %> ---- What actually would this syntax be? > <% @categories.each do |category| %> > <%= link_to category.name, :action => "list_by_cat", :id => > category.id %><br /> > <% end %> > > What is the variable name to get at the current controller?<% if controller.controller_name == ''admin'' -%> -- rick http://techno-weenie.net
I have a side navigation that i want to change based on the controller. How would i test for this in .rhtml. for example lets say i have an admin controller. Example -------------------- <% if @controller = admin %> ---- What actually would this syntax be? <% @categories.each do |category| %> <%= link_to category.name, :action => "list_by_cat", :id => category.id %><br /> <% end %> What is the variable name to get at the current controller? Thanks, Beau
Thanks Rick. -----Original Message----- From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Rick Olson Sent: Friday, December 02, 2005 12:55 PM To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: Re: [Rails] How to test for controller On 12/2/05, Beau O''Hara <bohara-Ani+Op4kYNUXWzRTk0ed69BPR1lH4CV8@public.gmane.org> wrote:> I have a side navigation that i want to change based on thecontroller.> How would i test for this in .rhtml. for example lets say i have an > admin controller. > > Example > -------------------- > <% if @controller = admin %> ---- What actually would this syntax be? > <% @categories.each do |category| %> > <%= link_to category.name, :action => "list_by_cat", :id => > category.id %><br /> <% end %> > > What is the variable name to get at the current controller?<% if controller.controller_name == ''admin'' -%> -- rick http://techno-weenie.net _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Yeah, and if it''s nav, you might even put it in the application controller directly (as a before_filter) and do the logic from within the LAYOUT files instead of the action .rhtml views. -----Original Message----- From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Tom Fakes Sent: Friday, December 02, 2005 1:05 PM To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: RE: [Rails] How to test for controller There is a reason the controller is called *controller*. The controller should be making this type of decision. I would do it this way: Class FooController < ApplicationController def bar @side_nav = :display_admin End def baz @side_nav = :hide_admin EndEnd In the view: <% if @side_nav == :display_admin %> ... <% end %> In your application controller, you can set a default value for the @side_nav variable to avoid needing to set it in every action -----Original Message----- From: Rick Olson [mailto:technoweenie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org] Sent: Friday, December 02, 2005 10:55 AM To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: Re: [Rails] How to test for controller On 12/2/05, Beau O''Hara <bohara-Ani+Op4kYNUXWzRTk0ed69BPR1lH4CV8@public.gmane.org> wrote:> I have a side navigation that i want to change based on thecontroller.> How would i test for this in .rhtml. for example lets say i have an > admin controller. > > Example > -------------------- > <% if @controller = admin %> ---- What actually would this syntax be? > <% @categories.each do |category| %> > <%= link_to category.name, :action => "list_by_cat", :id => > category.id %><br /> <% end %> > > What is the variable name to get at the current controller?<% if controller.controller_name == ''admin'' -%> -- rick http://techno-weenie.net _______________________________________________ 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