# Accessing a controller variable?

**URL:** <https://www.ruby-forum.com/t/accessing-a-controller-variable/107086>\
**Category:** Rails\
**Created:** [June 18, 2007, 1:01am UTC](https://www.ruby-forum.com/t/accessing-a-controller-variable/107086 "2007-06-18T01:01:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Parama](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b38774/32.png) [@Parama](https://www.ruby-forum.com/u/Parama)\
**Post date:** [June 18, 2007, 1:01am UTC](https://www.ruby-forum.com/t/accessing-a-controller-variable/107086/1 "2007-06-18T01:01:29Z")

</div>

I’m looking to find a way to access the data inside “@controller”.  
i.e. when you have @controller.inspect you will see a list of all data  
in them.

Are there anyway to do this?

My real aim is to get the name of the action automatically.

---

<div class="post-metadata">

**Author:** ![Parama](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b38774/32.png) [@Parama](https://www.ruby-forum.com/u/Parama)\
**Post date:** [June 18, 2007, 9:56am UTC](https://www.ruby-forum.com/t/accessing-a-controller-variable/107086/2 "2007-06-18T09:56:53Z")

</div>

Parama wrote:

> I’m looking to find a way to access the data inside “@controller”.  
> i.e. when you have @controller.inspect you will see a list of all data  
> in them.
> 
> Are there anyway to do this?
> 
> My real aim is to get the name of the action automatically.

if you have a class controller such as

ExampleController

you can access it by accessing it, really.  
ruby-render this (the ExampleController class will need to exist  
obviously):

ExampleController.methods.join(’ , ')

…and if you want it in a variable @controller, assign it.  
@controller = ExampleController  
and then, @controller.methods.inspect

hth

---

<div class="post-metadata">

**Author:** ![Parama](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b38774/32.png) [@Parama](https://www.ruby-forum.com/u/Parama)\
**Post date:** [June 18, 2007, 12:46pm UTC](https://www.ruby-forum.com/t/accessing-a-controller-variable/107086/3 "2007-06-18T12:46:44Z")

</div>

Hi –

On Sun, 17 Jun 2007, Parama wrote:

> I’m looking to find a way to access the data inside “@controller”.  
> i.e. when you have @controller.inspect you will see a list of all data  
> in them.
> 
> Are there anyway to do this?
> 
> My real aim is to get the name of the action automatically.

Have a look at the docs for ActionController::Base. There’s an  
attribute action\_name, and various other methods for extracting  
information.

David

–

- Books:  
RAILS ROUTING (new! [http://safari.awprofessional.com/9780321509246](http://safari.awprofessional.com/9780321509246))  
RUBY FOR RAILS ([Ruby for Rails](http://www.manning.com/black))
- Ruby/Rails training  
& consulting: Ruby Power and Light, LLC ([http://www.rubypal.com](http://www.rubypal.com))

---

<div class="post-metadata">

**Author:** ![Parama](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b38774/32.png) [@Parama](https://www.ruby-forum.com/u/Parama)\
**Post date:** [June 18, 2007, 9:12pm UTC](https://www.ruby-forum.com/t/accessing-a-controller-variable/107086/4 "2007-06-18T21:12:06Z")

</div>

Thanks David. it works
