# Detecting controller in application layout

**URL:** <https://www.ruby-forum.com/t/detecting-controller-in-application-layout/118404>\
**Category:** Rails\
**Created:** [October 26, 2007, 5:19pm UTC](https://www.ruby-forum.com/t/detecting-controller-in-application-layout/118404 "2007-10-26T17:19:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![miked](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@miked](https://www.ruby-forum.com/u/miked)\
**Post date:** [October 26, 2007, 5:19pm UTC](https://www.ruby-forum.com/t/detecting-controller-in-application-layout/118404/1 "2007-10-26T17:19:43Z")

</div>

Hi:

In the application layout file (application.rhtml in /views/layout/),  
I’m executing some logic to not load some files unless the user is  
logged in. THat’s working well, but I need to take that logic to the  
next step by doing the following:

I want to detect the controller that’s being called in the application  
layout file (I’m not using separate layouts, everything starts with  
application.rhtml), and execute logic based on the controller that’s  
detected. I was unable to find anything on the boards that helped; is  
there a way to detect the controller in a view?

Thanks very much in advance for your help!

Mike

---

<div class="post-metadata">

**Author:** ![miked](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@miked](https://www.ruby-forum.com/u/miked)\
**Post date:** [October 26, 2007, 5:24pm UTC](https://www.ruby-forum.com/t/detecting-controller-in-application-layout/118404/2 "2007-10-26T17:24:08Z")

</div>

Got it! Finally got the search string right:

```
    <%= params[:controller] %>
    <%= params[:action] %>

```

Thanks!

---

<div class="post-metadata">

**Author:** ![miked](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@miked](https://www.ruby-forum.com/u/miked)\
**Post date:** [October 27, 2007, 9:21am UTC](https://www.ruby-forum.com/t/detecting-controller-in-application-layout/118404/3 "2007-10-27T09:21:52Z")

</div>

Also works:

```
    <%= controller.controller_name %>
    <%= controller.action_name %>

```

–Andrew V.
