Tallboy
Tallboy

Reputation: 13407

How to get parent's controller_name?

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?

Upvotes: 0

Views: 1908

Answers (3)

George
George

Reputation: 680

Try controller.ancestors.include?(AdminController)

Upvotes: 1

treiff
treiff

Reputation: 1306

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.

Upvotes: 2

Gerry
Gerry

Reputation: 10497

Just use parent:

controller.class.parent

Upvotes: 1

Related Questions