I'm using controller.controller_name
to see where I'm at, and set the active
class on my menu.
The problem is I have a namespace: :admin
in my routes... and I need to check if I'm in any controller which inherits from AdminController
. Right now, controller_name
only pulls up the child controller's name... but really I need it to say 'admin'.
How can I access the name of the controller it's inheriting from?
If I'm understanding your question correctly, you could do:
controller.class.superclass
This should return AdminController
if your current controller is indeed inheriting from AdminController
.
Also, controller.class
should give you the fully namespaced controller name.
尝试controller.ancestors.include?(AdminController)
只需使用parent
:
controller.class.parent
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.