Rails follows a convention where controllers should inherit from ApplicationController
, which itself inherits from
ActionController::Base
. This pattern allows you to add application-wide functionality like authentication, authorization, and shared
methods in one place.
When controllers inherit directly from ActionController::Base
, they bypass ApplicationController
and miss out on any
shared functionality you’ve defined there. This can lead to inconsistent behavior across your application and make it harder to maintain common
controller logic.
Similarly, specialized frameworks like Avo have their own inheritance hierarchies. Avo controllers should inherit from
Avo::ResourcesController
to get framework-specific functionality. When they inherit from ApplicationController
or
ActionController::Base
instead, they lose important framework features and may not work correctly.
Following proper inheritance patterns makes your code more maintainable, ensures consistent behavior, and respects the architectural decisions of
the frameworks you’re using.
What is the potential impact?
Controllers that don’t follow proper inheritance patterns may miss critical application-wide functionality like authentication, authorization, or
error handling. This can create security vulnerabilities, inconsistent user experiences, and maintenance difficulties. Specialized controllers that
use incorrect base classes may not function properly within their intended frameworks.