abartov / bybeconv

Project Ben-Yehuda's content management system.
https://benyehuda.org/
Other
10 stars 5 forks source link

Extract FeaturedAuthor management code into a separate controller #360

Open damisul opened 1 month ago

damisul commented 1 month ago

We have bunch of actions in AdminController to handle FeaturedAuthor records:

  get 'admin/featured_author_list'
  get 'admin/featured_author/new' => 'admin#featured_author_new', as: 'featured_author_new'
  post 'admin/featured_author/create' => 'admin#featured_author_create', as: 'featured_author_create'
  get 'admin/featured_author/edit/:id' => 'admin#featured_author_edit', as: 'featured_author_edit'
  patch 'admin/featured_author/update' => 'admin#featured_author_update', as: 'featured_author_update'
  get 'admin/featured_author/destroy/:id' => 'admin#featured_author_destroy', as: 'featured_author_destroy'
  post 'admin/featured_author/add_feature' => 'admin#featured_author_add_feature', as: 'featured_author_add_feature'
  get 'admin/featured_author/delete_feature/:id' => 'admin#featured_author_delete_feature', as: 'featured_author_delete_feature'
  get 'admin/featured_author/:id' => 'admin#featured_author_show', as: 'featured_author_show'

It would be better to extract this logic into a separate controller FeaturedAuthorsController (and functionality to create feature records into FeaturedAuthorFeaturesController).

With this we can use resource notation in routes.rb like

resources :featured_author do
  member do
    resources :features, only [:create, :delete]
  end
end