# Getting Controller and Action Names

**URL:** <https://www.ruby-forum.com/t/getting-controller-and-action-names/47778>\
**Category:** Rails\
**Created:** [November 13, 2005, 10:11pm UTC](https://www.ruby-forum.com/t/getting-controller-and-action-names/47778 "2005-11-13T22:11:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [November 13, 2005, 10:11pm UTC](https://www.ruby-forum.com/t/getting-controller-and-action-names/47778/1 "2005-11-13T22:11:25Z")

</div>

I figured it would be the easiest thing to do but for some odd reason  
I am having a hard time to figure out how to do this.

I can get the action using @action\_name but I can’t get the  
controller using @controller\_name. What is the correct way to go  
about doing this?

Thanks for your help.

Your Friend,

John K.

–  
[http://www.soen.info](http://www.soen.info) - where software engineering knowledge gets indexed  
[http://cusec.soen.info](http://cusec.soen.info) - software engineering conference

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [November 13, 2005, 10:14pm UTC](https://www.ruby-forum.com/t/getting-controller-and-action-names/47778/2 "2005-11-13T22:14:25Z")

</div>

I use the following and it seems to work:

@params[:controller]

Regards,

Michael

John K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:  
I figured it would be the easiest thing to do but for some odd reason  
I am having a hard time to figure out how to do this.

I can get the action using @action\_name but I can’t get the  
controller using @controller\_name. What is the correct way to go  
about doing this?

Thanks for your help.

Your Friend,

John K.

–  
[http://www.soen.info](http://www.soen.info) - where software engineering knowledge gets indexed  
[http://cusec.soen.info](http://cusec.soen.info) - software engineering conference

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [November 13, 2005, 10:20pm UTC](https://www.ruby-forum.com/t/getting-controller-and-action-names/47778/3 "2005-11-13T22:20:26Z")

</div>

I use controller.controller\_name

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [November 13, 2005, 10:17pm UTC](https://www.ruby-forum.com/t/getting-controller-and-action-names/47778/4 "2005-11-13T22:17:26Z")

</div>

And to see the other params available:

\<%= debug(params) %\>

within your view.

Regards,

Michael

John K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:  
I figured it would be the easiest thing to do but for some odd reason  
I am having a hard time to figure out how to do this.

I can get the action using @action\_name but I can’t get the  
controller using @controller\_name. What is the correct way to go  
about doing this?

Thanks for your help.

Your Friend,

John K.

–  
[http://www.soen.info](http://www.soen.info) - where software engineering knowledge gets indexed  
[http://cusec.soen.info](http://cusec.soen.info) - software engineering conference

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [November 13, 2005, 10:23pm UTC](https://www.ruby-forum.com/t/getting-controller-and-action-names/47778/5 "2005-11-13T22:23:26Z")

</div>

Not sure why my last reply didn’t get to this list. I’ll try again - if  
it shows up then sorry for the duplicate post:

@params[:controller]

Regards,

Michael

John K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:  
I figured it would be the easiest thing to do but for some odd reason  
I am having a hard time to figure out how to do this.

I can get the action using @action\_name but I can’t get the  
controller using @controller\_name. What is the correct way to go  
about doing this?

Thanks for your help.

Your Friend,

John K.

–  
[http://www.soen.info](http://www.soen.info) - where software engineering knowledge gets indexed  
[http://cusec.soen.info](http://cusec.soen.info) - software engineering conference

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [November 13, 2005, 10:50pm UTC](https://www.ruby-forum.com/t/getting-controller-and-action-names/47778/6 "2005-11-13T22:50:27Z")

</div>

On Sun, 2005-11-13 at 13:12 -0800, Michael wrote:

> I use the following and it seems to work:
> 
> @params[:controller]

Michael,

Just a quick, FYI…

@params, @request, etc… are deprecated.[1]

You can and should now use params, request, etc.

[1] [http://rubyurl.com/xaG](http://rubyurl.com/xaG) (params v.s. @params in rails?)

Cheers,

Robby

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [November 14, 2005, 12:41am UTC](https://www.ruby-forum.com/t/getting-controller-and-action-names/47778/7 "2005-11-14T00:41:36Z")

</div>

Thank you Robby! Interestingly, I am new to Rails - I think I got the  
info from the agile book. I will switch accordingly…

Michael

Robby R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:  
On Sun, 2005-11-13 at 13:12 -0800, Michael wrote:

> I use the following and it seems to work:
> 
> @params[:controller]

Michael,

Just a quick, FYI…

@params, @request, etc… are deprecated.[1]

You can and should now use params, request, etc.

[1] [http://rubyurl.com/xaG](http://rubyurl.com/xaG) (params v.s. @params in rails?)

Cheers,

Robby
