# Getting a list of possible actions from a controller

**URL:** <https://www.ruby-forum.com/t/getting-a-list-of-possible-actions-from-a-controller/70353>\
**Category:** Rails\
**Created:** [September 28, 2006, 5:01pm UTC](https://www.ruby-forum.com/t/getting-a-list-of-possible-actions-from-a-controller/70353 "2006-09-28T17:01:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mike](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/58f4c7/32.png) [@mike](https://www.ruby-forum.com/u/mike)\
**Post date:** [September 28, 2006, 5:01pm UTC](https://www.ruby-forum.com/t/getting-a-list-of-possible-actions-from-a-controller/70353/1 "2006-09-28T17:01:19Z")

</div>

I’m working on a role based authentication scheme.

It defines roles, which are assigned to users.

The roles are action-\>controller pairs, and if a user has a role  
containing an action/controller, they my access that pair.

Works great.

However, the administration needs to auto-discover all possible  
action-\>controller pairs for the entire application.

Now, I can get a list of all controllers, no problem.

The problem is that the controller has no way to tell me what it’s  
possible actions are. I can get function lists, hidden actions, and all  
that, but no way of getting just plain old actions from a controller  
class or an instantiated controller.

Any ideas?

---

<div class="post-metadata">

**Author:** ![mike](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/58f4c7/32.png) [@mike](https://www.ruby-forum.com/u/mike)\
**Post date:** [September 28, 2006, 5:16pm UTC](https://www.ruby-forum.com/t/getting-a-list-of-possible-actions-from-a-controller/70353/2 "2006-09-28T17:16:22Z")

</div>

As ‘actions’ are simply the methods defined on the controller, this  
should  
work (though I can’t test it right now):

ControllerClass.instance\_methods -  
ActionController::Base.instance\_methods

Jason

---

<div class="post-metadata">

**Author:** ![mike](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/58f4c7/32.png) [@mike](https://www.ruby-forum.com/u/mike)\
**Post date:** [September 28, 2006, 5:28pm UTC](https://www.ruby-forum.com/t/getting-a-list-of-possible-actions-from-a-controller/70353/3 "2006-09-28T17:28:26Z")

</div>

On 28 September 2006 19:11, Jason R. wrote:

> As ‘actions’ are simply the methods defined on the controller, this should  
> work (though I can’t test it right now):
> 
> ControllerClass.instance\_methods - ActionController::Base.instance\_methods  
> This won’t work because not all instance methods are considered actions.  
> Some  
> methods are hidden (with hide\_actions method).

You’d better use class method ActionController::Base.action\_methods or  
it’s  
instance method analogue.

---

<div class="post-metadata">

**Author:** ![mike](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/58f4c7/32.png) [@mike](https://www.ruby-forum.com/u/mike)\
**Post date:** [September 28, 2006, 5:54pm UTC](https://www.ruby-forum.com/t/getting-a-list-of-possible-actions-from-a-controller/70353/4 "2006-09-28T17:54:34Z")

</div>

Ah, so there is something like that. You’ll have to go diving around in  
ActionController itself to find such methods though, they aren’t on the  
documentation most of the time.

Jason

---

<div class="post-metadata">

**Author:** ![mike](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/58f4c7/32.png) [@mike](https://www.ruby-forum.com/u/mike)\
**Post date:** [September 28, 2006, 7:22pm UTC](https://www.ruby-forum.com/t/getting-a-list-of-possible-actions-from-a-controller/70353/5 "2006-09-28T19:22:57Z")

</div>

The “user” engine does this in the Permission model  
(synchronize\_with\_controllers method). Take a look at that code for  
ideas.

c.

Mike wrote:

> I’m working on a role based authentication scheme.
> 
> It defines roles, which are assigned to users.
> 
> The roles are action-\>controller pairs, and if a user has a role  
> containing an action/controller, they my access that pair.
> 
> Works great.
> 
> However, the administration needs to auto-discover all possible  
> action-\>controller pairs for the entire application.
> 
> Now, I can get a list of all controllers, no problem.
> 
> The problem is that the controller has no way to tell me what it’s  
> possible actions are. I can get function lists, hidden actions, and all  
> that, but no way of getting just plain old actions from a controller  
> class or an instantiated controller.
> 
> Any ideas?
