Reputation: 53
Say I'm within a controller and I want to get a list of the actions and HTTP verbs that it supports, how would I do that?. E.g.
controller.actions # { [ :show, :get ], [ :update, :put ], . . . }
Or something equivalent.
Upvotes: 4
Views: 589
Reputation: 9845
Something like this:
controller = "users"
controller_routes = []
Rails.application.routes.routes.each do |route|
if route.to_s.include?(":controller=>\"#{controller}\"")
controller_routes << route
end
end
puts controller_routes
You get the idea.
Upvotes: 3