# How to determine the current controller?

**URL:** <https://rubytalk.org/t/how-to-determine-the-current-controller/47306>\
**Category:** ruby-talk\
**Created:** [24 June 2008 10:39 UTC](https://rubytalk.org/t/how-to-determine-the-current-controller/47306 "2008-06-24T10:39:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sven\_Gehring](https://avatars.discourse-cdn.com/v4/letter/s/49beb7/32.png) [@Sven\_Gehring](https://rubytalk.org/u/Sven_Gehring)\
**Post date:** [24 June 2008 10:39 UTC](https://rubytalk.org/t/how-to-determine-the-current-controller/47306/1 "2008-06-24T10:39:33Z")

</div>

Hi guys,

I want to build a generic navigation menu with partials in the style of

if current\_controller == 'abcd'  
render pratial 'abscd'

How can I determine the current controller from within the layout .rhtml  
file without taking care of what action is executed?

If I use current\_page?(:controller =\> 'abcd') it works as long as the  
current\_page is [http://localhost:3000/abcd](http://localhost:3000/abcd)

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![nas](https://avatars.discourse-cdn.com/v4/letter/n/e9c0ed/32.png) [@nas](https://rubytalk.org/u/nas)\
**Post date:** [24 June 2008 12:03 UTC](https://rubytalk.org/t/how-to-determine-the-current-controller/47306/2 "2008-06-24T12:03:08Z")

</div>

you have an instance variable available in your views called  
@controller

hence you can use something like

if @controller.controller\_name == 'abcd'  
do something  
else  
do somthing else  
end

> **···**
>
> On Jun 24, 11:39 am, Sven Gehring \<sven.gehr...@mac.com\> wrote:
> 
> > Hi guys,
> > 
> > I want to build a generic navigation menu with partials in the style of
> > 
> > if current\_controller == 'abcd'  
> > render pratial 'abscd'
> > 
> > How can I determine the current controller from within the layout .rhtml  
> > file without taking care of what action is executed?
> > 
> > If I use current\_page?(:controller =\> 'abcd') it works as long as the  
> > current\_page ishttp://localhost:3000/abcd  
> > --  
> > Posted viahttp://www.ruby-forum.com/.
