Hi, How do you share common logic between an “admin” controller and a “normal” controller.
I have this scenario where I have an
class Organization < ApplicationRecord name, description, published_at belongs_to :user end
A user can create and manage their organizations. But only and administrator can publish an organization. Also an administrator can see all the organizations, from all the users, even the unpublished ones
class OrganizationsController < ApplicationController # accepts only name and description for create/update and allows index/show/destroy only for the organizations of the user end
class Admin::OrganizationsController < ApplicationController # accepts published_at from the form and allows create/read/update/delete of all the organizations. end
Naturally there is some common logic between the controllers. Like the list of accepted params. The create method is the same. The update is the same. But they redirect to different places on success:
- OrganizationsController redirects to organizations_path
- Admin::OrganizatiosController redirects to admin_organizations_path
What do you guys do?
- Extend - eg Admin::OrganizationsController < OrganizationsController
- Have a common concern?
- Implement the two controllers completely separately?
- Have one controller that manages both admin and non-admin logic?
- Something else.