.vbw-planning/milestones/07-rails-audit-and-refactoring/03-controller-route-refactoring/01-PLAN.md
Extract the custom scrape action from ItemsController into a dedicated ItemScrapesController following CRUD conventions (C1), and simplify the over-defensive logging pattern (C8).
app/controllers/source_monitor/items_controller.rb has a scrape action (lines 39-85) with a TODO comment acknowledging this debtpost :scrape, on: :member in routes.rb line 20 -- violates everything-is-CRUD conventionlog_manual_scrape (lines 109-116) has unnecessary defined?(Rails) checks and rescue StandardErrorapp/views/source_monitor/items/_details.html.erb:165 uses scrape_item_path(item)Create test/controllers/source_monitor/item_scrapes_controller_test.rb with:
create enqueues scrape via turbo_stream format (mock Enqueuer)create with html format redirects to item pathcreate when enqueue fails returns unprocessable_entitycreate when item already enqueued returns ok with noticeUse existing test patterns: create_source!, WebMock stubs, fixtures :users.
Create app/controllers/source_monitor/item_scrapes_controller.rb:
ItemScrapesController < ApplicationControllerinclude ActionView::RecordIdentifierbefore_action :set_itemcreate action with the scrape logic extracted from ItemsControllerscrape_flash_payload as private methodRails.logger.info(...) without defensive checks or rescueIn config/routes.rb, replace:
resources :items, only: %i[index show] do
post :scrape, on: :member
end
with:
resources :items, only: %i[index show] do
resource :scrape, only: :create, controller: "item_scrapes"
end
app/views/source_monitor/items/_details.html.erb:165 to use the new route helper (item_scrape_path(item) instead of scrape_item_path(item))scrape action, scrape_flash_payload, and log_manual_scrape from ItemsControllerscrape from before_action :set_item, only: %i[show scrape] (becomes only: :show)bin/rails test -- all passbin/rubocop -- zero offensesbin/rails routes -g scrape shows new path