Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 28, 2026

Extract FeaturedAuthor Management to Separate Controllers

This PR extracts FeaturedAuthor management code from AdminController into dedicated controllers, following the same pattern already established for FeaturedContent.

Summary of Changes

  1. Created new controllers:

    • Admin::FeaturedAuthorsController - handles CRUD operations for FeaturedAuthor records
    • Admin::FeaturedAuthorFeaturesController - manages feature date ranges
  2. Updated routes:

    • Changed from custom routes to RESTful resource notation
    • Nested features routes under featured_authors
  3. Created new views:

    • Moved views from app/views/admin/featured_author_* to app/views/admin/featured_authors/
    • Updated views to use RESTful path helpers
    • Improved form using Rails conventions and safe navigation
    • Deleted old legacy templates
  4. Added model validations:

    • FeaturedAuthor now validates presence of title and body
    • FeaturedAuthorFeature validates presence of fromdate and todate
    • Made person association optional to handle legacy data
  5. Created comprehensive tests:

    • Full controller specs for both new controllers
    • Tests cover CRUD operations, validations, and error handling
  6. Removed legacy code:

    • Removed all featured_author methods from AdminController
    • Removed corresponding tests from AdminController spec

Code Review Improvements

  • Fixed edit link in index view to use correct path helper
  • Fixed CSS typo (alignment → text-align)
  • Made flash handling consistent across all actions
  • Changed destroy! to destroy for graceful error handling
  • Made person association optional to handle legacy data
  • Fixed test parameter names to match implementation
  • Fixed person_id handling to use strong params consistently in both create and update
  • Removed old legacy view templates

Plan

  • Explore the codebase to understand current implementation
  • Create Admin::FeaturedAuthorsController with CRUD actions
  • Create Admin::FeaturedAuthorFeaturesController for feature management
  • Move views to app/views/admin/featured_authors/
  • Update view references to use new route helpers
  • Update routes.rb to use resource notation with nested features
  • Remove featured_author methods from AdminController
  • Create comprehensive tests for both new controllers
  • Add i18n translations for featured_author_features
  • Add validations to FeaturedAuthor and FeaturedAuthorFeature models
  • Fix linting issues in views and controllers
  • Run new controller tests - all passing
  • Remove old tests from AdminController spec
  • Verify all controller tests pass
  • Address code review feedback
  • Fix person_id to use strong params consistently
  • Remove old legacy view templates
Original prompt

This section details on the original issue you should resolve

<issue_title>Extract FeaturedAuthor management code into a separate controller</issue_title>
<issue_description>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
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Extract FeaturedAuthor management code into separate controller Extract FeaturedAuthor management into dedicated controllers Jan 28, 2026
Copilot AI requested a review from abartov January 28, 2026 19:03
private

def featured_author_feature_params
params.require(:featured_author_feature).permit(:fromdate, :todate)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rails/StrongParametersExpect: Use expect(featured_author_feature: [:fromdate, :todate]) instead.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Extracts FeaturedAuthor management out of AdminController into dedicated admin controllers, aligning the implementation with the existing “FeaturedContent” pattern and switching to RESTful routes/views.

Changes:

  • Added Admin::FeaturedAuthorsController (CRUD) and Admin::FeaturedAuthorFeaturesController (feature period management) with new controller specs.
  • Replaced legacy custom routes with RESTful resources routes and updated admin navigation accordingly.
  • Added model validations and i18n keys to support failure messaging for feature period creation.

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
spec/controllers/admin_controller_spec.rb Removes legacy FeaturedAuthor specs tied to AdminController actions.
spec/controllers/admin/featured_authors_controller_spec.rb Adds controller specs for FeaturedAuthor CRUD.
spec/controllers/admin/featured_author_features_controller_spec.rb Adds controller specs for creating/deleting feature periods.
config/routes.rb Adds RESTful admin routes for featured authors/features and removes legacy custom routes.
config/locales/he.yml Adds i18n key for featured-author feature creation failure.
config/locales/en.yml Adds i18n key for featured-author feature creation failure.
app/views/admin/index.html.haml Updates admin dashboard link to the new RESTful FeaturedAuthors index.
app/views/admin/featured_authors/show.html.haml New admin show page for FeaturedAuthor + feature period management UI.
app/views/admin/featured_authors/index.html.haml New admin index for FeaturedAuthors using RESTful path helpers.
app/views/admin/featured_authors/new.html.haml New admin “new featured author” page using shared form partial.
app/views/admin/featured_authors/edit.html.haml New admin “edit featured author” page using shared form partial.
app/views/admin/featured_authors/_form.html.haml New shared form partial (title/body + linked author autocomplete).
app/models/featured_author.rb Makes person optional and adds presence validations for title/body.
app/models/featured_author_feature.rb Adds presence validations for fromdate/todate.
app/controllers/admin_controller.rb Removes legacy FeaturedAuthor actions and strong params helper.
app/controllers/admin/featured_authors_controller.rb New RESTful controller for FeaturedAuthor CRUD.
app/controllers/admin/featured_author_features_controller.rb New controller for creating/destroying FeaturedAuthorFeature records.

Comment on lines 17 to 20
def create
@fc = FeaturedAuthor.new(fa_params)
@fc.person_id = params[:person_id]
@fc.user = current_user
Copy link

Copilot AI Jan 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

person_id is being passed as a top-level param and manually assigned in create, but update never applies params[:person_id]. As a result, changing the linked author in the edit form won’t persist (the UI posts person_id, but the controller ignores it). Consider accepting person_id via strong params (e.g., include it in fa_params) and updating both create and update to use it consistently.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit 185d2e4. Added person_id to strong params (fa_params) so both create and update actions now handle the linked author consistently.

Comment on lines +19 to +22
resources :featured_authors do
resources :features, controller: 'featured_author_features', only: %i(create)
end
resources :featured_author_features, only: %i(destroy)
Copy link

Copilot AI Jan 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR description says the old app/views/admin/featured_author_* templates were moved to app/views/admin/featured_authors/, but the legacy templates still exist in the repo and reference the removed admin#featured_author_* routes. Consider deleting the unused templates (and any related partials) to avoid dead code and future confusion.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit 185d2e4. Deleted all old legacy templates:

  • app/views/admin/featured_author_edit.html.haml
  • app/views/admin/featured_author_list.html.haml
  • app/views/admin/featured_author_new.html.haml
  • app/views/admin/featured_author_show.html.haml
  • app/views/admin/_featured_author_form.html.haml

@abartov
Copy link
Collaborator

abartov commented Jan 29, 2026

@copilot -- address the code review comments.

- Include person_id in strong params for both create and update actions
- Update test to pass person_id inside featured_author params
- Delete old legacy view templates that are no longer used

Co-authored-by: abartov <[email protected]>
@abartov abartov marked this pull request as ready for review January 29, 2026 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extract FeaturedAuthor management code into a separate controller

2 participants