I''m new to Rails and am trying to work though an issue. I have a navigation menu that is part of the layout shared by all my views. When a user selects an item in the navigation menu and the controller is invoked and the view displayed I''d like to be able to change the navigation menu to hilight the menu item corresponding to the current view. Is there a way for a layout to know the name of the controller and action that was invoked (besides setting some sort of global variable in the controller or view)? Thanks in advance, Bruce
On 9.10.2005, at 19.21, Bruce Cohen wrote:> I''m new to Rails and am trying to work though an issue. I have a > navigation menu that is part of the layout shared by all my views. > When a user selects an item in the navigation menu and the > controller is invoked and the view displayed I''d like to be able to > change > the navigation menu to hilight the menu item corresponding to the > current view. > > Is there a way for a layout to know the name of the controller and > action that was invoked > (besides setting some sort of global variable in the controller or > view)?See link_to_unless_current [1] and link_to_unless [2]. You can build a fairly clever navigation system using them (and their block parameters). //jarkko [1] http://rails.rubyonrails.com/classes/ActionView/Helpers/ UrlHelper.html#M000309 [2] http://rails.rubyonrails.com/classes/ActionView/Helpers/ UrlHelper.html#M000310> > Thanks in advance, > Bruce > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > >-- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
I''m also new to rails, but I think I can actually answer your question ;). Layouts have automatic access to a controller variable which has a method that returns the controller name and also an attribute that contains the action name. So you can check: controller.controller_name (or controller_class_name) for the controller name and controller.action_name for the action name. hth, joshua On 10/9/05, Bruce Cohen <bhcohen-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''m new to Rails and am trying to work though an issue. I have a > navigation menu that is part of the layout shared by all my views. > When a user selects an item in the navigation menu and the controller > is invoked and the view displayed I''d like to be able to change > the navigation menu to hilight the menu item corresponding to the > current view. > > Is there a way for a layout to know the name of the controller and > action that was invoked > (besides setting some sort of global variable in the controller or > view)? > > Thanks in advance, > Bruce > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >