Skip to content

ApplicationController refactoring #2814

@goosys

Description

@goosys

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 ApplicationController has 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).
  • 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 or render turbo_stream: for Hotwire.
    • Make it possible to use Administrate’s advanced CRUD functionalities for building API controllers.

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! 🙏

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions