# Getting the Controller name from a layout

**URL:** <https://www.ruby-forum.com/t/getting-the-controller-name-from-a-layout/112131>\
**Category:** Rails\
**Created:** [August 15, 2007, 7:06pm UTC](https://www.ruby-forum.com/t/getting-the-controller-name-from-a-layout/112131 "2007-08-15T19:06:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![chrismalek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/6de8d8/32.png) [@chrismalek](https://www.ruby-forum.com/u/chrismalek)\
**Post date:** [August 15, 2007, 7:06pm UTC](https://www.ruby-forum.com/t/getting-the-controller-name-from-a-layout/112131/1 "2007-08-15T19:06:48Z")

</div>

I’m sure it’s a simple answer, but I’m trying to access which controller  
a view is being displayed from within a layout. Basically what I want  
to do is pull out the controller name from the URL.

For example:  
/localhost/my\_controller/new

I want to be able to get out ‘my\_controller’ when my standard-layout is  
generated, and from there render different menu items based on the  
options that pertain to that particular controller.

Help would be appreciated, thanks in advance

---

<div class="post-metadata">

**Author:** ![chrismalek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/6de8d8/32.png) [@chrismalek](https://www.ruby-forum.com/u/chrismalek)\
**Post date:** [August 15, 2007, 7:26pm UTC](https://www.ruby-forum.com/t/getting-the-controller-name-from-a-layout/112131/2 "2007-08-15T19:26:16Z")

</div>

> I’m sure it’s a simple answer, but I’m trying to access which controller  
> a view is being displayed from within a layout. Basically what I want  
> to do is pull out the controller name from the URL.
> 
> For example:  
> /localhost/my\_controller/new
> 
> I want to be able to get out ‘my\_controller’ when my standard-layout is  
> generated, and from there render different menu items based on the  
> options that pertain to that particular controller.

params[:controller] should have it…

We put the below in our layout so we can view the source and see the  
host,  
controller, and action for any given page… sometimes it’s useful in  
debugging.

---

<div class="post-metadata">

**Author:** ![chrismalek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/6de8d8/32.png) [@chrismalek](https://www.ruby-forum.com/u/chrismalek)\
**Post date:** [August 15, 2007, 7:27pm UTC](https://www.ruby-forum.com/t/getting-the-controller-name-from-a-layout/112131/3 "2007-08-15T19:27:16Z")

</div>

controller.controller\_name

On Aug 15, 10:06 am, Chris M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![chrismalek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/6de8d8/32.png) [@chrismalek](https://www.ruby-forum.com/u/chrismalek)\
**Post date:** [August 15, 2007, 7:28pm UTC](https://www.ruby-forum.com/t/getting-the-controller-name-from-a-layout/112131/4 "2007-08-15T19:28:49Z")

</div>

beauty, thanks. figured it was real simple!
