Getting a list of possible actions from a controller

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?

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

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.

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

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?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs