Emmanuel Oga
2007-Jun-13 20:45 UTC
Can i know the name of my current controller in my views?
Just that: can i know the name of my current controller in my views? I want to highlite in my main template (the one i use for all the pages) the current page, to do that i need to know the current controller, and i don''t want to use a controller variable with a before filter because i think there should be a easiest way. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Tyler MacDonald
2007-Jun-13 20:48 UTC
Re: Can i know the name of my current controller in my views?
Emmanuel Oga <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Just that: can i know the name of my current controller in my views?The current controller is always in the "@controller" variable, so: @controller.class.to_s If you want the name as a string. If you just want to test if the controller is a certain type use the "===" operator instead, eg; if WidgetController === @controller # running under widgetcontroller else # ... end Cheers, Tyler --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Trevor Squires
2007-Jun-13 21:13 UTC
Re: Can i know the name of my current controller in my views?
umm.... controller.controller_name might be a better solution. for FooController you get ''foo'' HTH Trevor On 6/13/07, Tyler MacDonald <google.com-oTuY4Vk9bUDG8MNy1oJpyw@public.gmane.org> wrote:> > Emmanuel Oga <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > > Just that: can i know the name of my current controller in my views? > > The current controller is always in the "@controller" variable, so: > > @controller.class.to_s > > If you want the name as a string. If you just want to test if the > controller is a certain type use the "===" operator instead, eg; > > if WidgetController === @controller > # running under widgetcontroller > else > # ... > end > > Cheers, > Tyler > > > >-- -- Trevor Squires http://somethinglearned.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---