How can I know the current controller name in a layout file such as application.rhtml? I found I can do: def name self.class.controller_name end in the controller itself, and that gets me controller.name in my layout, but is there a better way that repeating that code in every controller? Or where can I put that method so it''s available in all views/layouts ? Thanks, -- Greg Donald Zend Certified Engineer MySQL Core Certification destiney.com
im pretty sure you can go params[:controller] On 8/19/05, Greg Donald <destiney-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> How can I know the current controller name in a layout file such as > application.rhtml? > > I found I can do: > > def name > self.class.controller_name > end > > in the controller itself, and that gets me controller.name in my > layout, but is there a better way that repeating that code in every > controller? Or where can I put that method so it''s available in all > views/layouts ? > > Thanks, > > > -- > Greg Donald > Zend Certified Engineer > MySQL Core Certification > destiney.com > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > lists.rubyonrails.org/mailman/listinfo/rails >-- Zachery Hostens <zacheryph-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
There is actually already a method named ''controller'' in the view. You can do stuff like: controller.action_name As well as: controller.name Hope that helps! On 8/19/05, Zachery Hostens <zacheryph-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> im pretty sure you can go params[:controller] > > On 8/19/05, Greg Donald <destiney-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > How can I know the current controller name in a layout file such as > > application.rhtml? > > > > I found I can do: > > > > def name > > self.class.controller_name > > end > > > > in the controller itself, and that gets me controller.name in my > > layout, but is there a better way that repeating that code in every > > controller? Or where can I put that method so it''s available in all > > views/layouts ? > > > > Thanks, > > > > > > -- > > Greg Donald > > Zend Certified Engineer > > MySQL Core Certification > > destiney.com > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > lists.rubyonrails.org/mailman/listinfo/rails > > > > > -- > Zachery Hostens <zacheryph-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > lists.rubyonrails.org/mailman/listinfo/rails >-- - Aaron ''Jomdom'' Ransley - Web: jomdom.net - Mail: jomdom-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
controller.name Should be: controller.controller_name Up too late again :) On 8/20/05, Aaron Ransley <jomdom-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> There is actually already a method named ''controller'' in the view. You > can do stuff like: > > controller.action_name > > As well as: > > controller.name > > Hope that helps!
Please explain the syntax of contrller.name In my Ruby-awareness, that should be a attribute name of an object called controller. Where does that come from? Is it a type of helper? Where is the class file? Documentation? I couldn''t find anything in the Agile book about. Thanks in advance John B ----- Original Message ----- From: "Aaron Ransley" <jomdom-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> To: <rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org> Sent: Friday, August 19, 2005 11:12 PM Subject: Re: [Rails] controller name controller.name Should be: controller.controller_name Up too late again :) On 8/20/05, Aaron Ransley <jomdom-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> There is actually already a method named ''controller'' in the view. You > can do stuff like: > > controller.action_name > > As well as: > > controller.name > > Hope that helps!_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org lists.rubyonrails.org/mailman/listinfo/rails
On 11/12/05, speechexpert <speechexpert-rphTv4pjVZMJGwgDXS7ZQA@public.gmane.org> wrote:> Please explain the syntax of contrller.name In my Ruby-awareness, that > should be a attribute name of an object called controller. > Where does that come from? Is it a type of helper? Where is the class file? > Documentation? > I couldn''t find anything in the Agile book about. > Thanks in advance > John B >controller is an attr_accessor of ActionView::Base (the base class of all views): rails.rubyonrails.com/classes/ActionView/Base.html This means that when the view is being prepared, @controller is set to an instance of the current controller. Same thing for params, request, session, etc. -- rick techno-weenie.net