15

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

NullVoxPopuli
  • 61,906
  • 73
  • 206
  • 352

2 Answers2

17

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!

LuisVM
  • 2,763
  • 3
  • 20
  • 22
16

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).

Community
  • 1
  • 1
ScottJShea
  • 7,041
  • 11
  • 44
  • 67