I have many controllers that will have some similar behavior, e.g. the user should be logged in, some scope needs to be set up, the current_account / current_user needs to be set and permissions cached.
I am think of using a standard controller and subclassing that.
class MyStandardController < ApplicationController
before_filter :xyz
end
class SomeController < MyStandardController
end
What I'm wondering is do I need to / when to call super
at all?
You don't need to ever call super
inside a controller that inherits from another controller; in fact, doing so would probably be kind of weird. Super executes a method of the same name from a superclass, and you probably won't have any methods on MyStandardController
you'll redefine in its children.
The main reason to do this is, as you said yourself, to get filters and methods easily namespaced across controllers. We do something similar to this in our apps, where one area of the site with very similar behavior will inherit from a controller (like ShoppingController) that has a section of private convenience methods that are usable only across all its children.
However, realistically speaking, it would probably be better to have modules that implement the functionality you want, and include them in the controllers you want. Eventually you'll probably want something from one controller on another, and doing that is way easier with modules than with complicated inheritance hierarchies.