# Can i know the name of my current controller in my views?

**URL:** <https://www.ruby-forum.com/t/can-i-know-the-name-of-my-current-controller-in-my-views/106768>\
**Category:** Rails\
**Created:** [June 13, 2007, 10:45pm UTC](https://www.ruby-forum.com/t/can-i-know-the-name-of-my-current-controller-in-my-views/106768 "2007-06-13T22:45:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![emmanueloga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ecae2f/32.png) [@emmanueloga](https://www.ruby-forum.com/u/emmanueloga)\
**Post date:** [June 13, 2007, 10:45pm UTC](https://www.ruby-forum.com/t/can-i-know-the-name-of-my-current-controller-in-my-views/106768/1 "2007-06-13T22:45:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![emmanueloga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ecae2f/32.png) [@emmanueloga](https://www.ruby-forum.com/u/emmanueloga)\
**Post date:** [June 13, 2007, 10:49pm UTC](https://www.ruby-forum.com/t/can-i-know-the-name-of-my-current-controller-in-my-views/106768/2 "2007-06-13T22:49:35Z")

</div>

Emmanuel O. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![emmanueloga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ecae2f/32.png) [@emmanueloga](https://www.ruby-forum.com/u/emmanueloga)\
**Post date:** [June 13, 2007, 11:14pm UTC](https://www.ruby-forum.com/t/can-i-know-the-name-of-my-current-controller-in-my-views/106768/3 "2007-06-13T23:14:39Z")

</div>

umm… controller.controller\_name might be a better solution.

for FooController you get ‘foo’

HTH  
Trevor

On 6/13/07, Tyler MacDonald [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 

## –

Trevor S.  
[http://somethinglearned.com](http://somethinglearned.com)
