I did MyController.methods
and it listed EVERYTHING... things I didn't even know controllers could do!
How do I return the list of actions, such as create
, edit
, new
, destroy
, other_action
, other_non_protected_or_private_method
?
Using Ruby on Rails 2.3.8
Action Controller is the C in MVC. After the router has determined which controller to use for a request, the controller is responsible for making sense of the request and producing the appropriate output.
Adding an Action to a Controller You add a new action to a controller by adding a new method to the controller. For example, the controller in Listing 1 contains an action named Index() and an action named SayHello(). Both methods are exposed as actions.
Not sure if this will work in 2.38 but I figured it was worth a shot:
To quote the relevant part:
To get all the actions in a controller, use action_methods
PostsController.action_methods
This will return a Set containing a list of all of the methods in your controller that are "actions" (using the same logic Rails uses to decide whether a method is a valid action to route to).
Use #instance_methods(false) to retrieve only controller's specific actions:
CustomController.instance_methods(false)
=> ["index", "update", "show", "custom_action", "another_action"]
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With