Apply a Rails controller filter to all controllers of a specific namespace?

I have a bunch of controllers in the namespace Foo. I would like to apply before_filter 'require_user'to all of them, but not to other controllers that do not belong to the namespace Foo.

Is there a way to do this other than explicitly calling the before_filter method in each controller?

+5
source share
2 answers

You can have a class FooControllerthat includes before_filterand then use it as a base class for all controllers in this namespace.

+4
source

. , - ObjectSpace.

+1

All Articles