-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
I fully understand that this might be overly presumptuous, and I truly don’t mean to overstep, but I’d really like to refactor the ApplicationController.
Here are some reasons why:
- Improved maintainability
- The current
ApplicationControllerhas many methods, making it difficult to read and maintain. - The order of methods is not well-structured, making it hard to identify which method belongs to which functionality.
- Many action methods are too fat, requiring developers to copy entire methods for partial customization, which leads to inconsistencies during version upgrades.
- I'd like to remove methods that are unrelated to CRUD (e.g., view-related methods).
- The current
- Better customization
- Methods should be split into single-responsibility functions so developers can override only the necessary parts.
- Built-in features like Kaminari, search, and filtering should be easily replaceable with alternatives like Pagy or Ransack.
- Developers should be able to pick and include only the necessary modules from concerns to create a custom
ApplicationController.
- Enhanced functionality
- Support multiple response formats using
respond_to, allowing responses like JSON orrender turbo_stream:for Hotwire. - Make it possible to use Administrate’s advanced CRUD functionalities for building API controllers.
- Support multiple response formats using
I’ve done a simple experiment, and ideally, it should look something like this: goosys@20cf3a7
https://github.com/goosys/administrate/blob/labo/application_controller_refactoring/app/controllers/administrate/application_controller.rb
https://github.com/goosys/administrate/tree/labo/application_controller_refactoring/app/controllers/concerns/administrate
With this level of simplicity (around 7 methods, ~70 lines), even if developers create their own custom ApplicationController, they won’t have major conflicts with the latest codebase, or at least the necessary adjustments will be minimal.
Again, I genuinely don’t mean to be intrusive, but I really believe this would be beneficial. I’d love to hear your thoughts! 🙏