I know about controller_name returning a string containing the controller’s name but how can I retrieve the controller class (or object) from within a helper?
EDIT: The solution should also work when the controller is namespaced (eg. Admin::PostsController)
You can use the
constantizemethod, like:Though I’m not sure how it will behave if you have a namespaced controller.
Update:
That one won’t work for all controller names and/or namespaces. Though one can use the
#controllermethod in combination with#class: