Class: SourceMonitor::BulkScrapeEnablementsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/source_monitor/bulk_scrape_enablements_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/source_monitor/bulk_scrape_enablements_controller.rb', line 5

def create
  source_ids = resolve_source_ids

  if source_ids.empty?
    handle_empty_selection
    return
  end

  updated_count = Source.enable_scraping!(source_ids)

  respond_to do |format|
    format.turbo_stream do
      responder = SourceMonitor::TurboStreams::StreamResponder.new
      responder.toast(
        message: "Scraping enabled for #{updated_count} #{'source'.pluralize(updated_count)}.",
        level: :success
      )
      responder.redirect(source_monitor.sources_path)
      render turbo_stream: responder.render(view_context)
    end
    format.html do
      redirect_to source_monitor.sources_path,
        notice: "Scraping enabled for #{updated_count} #{'source'.pluralize(updated_count)}."
    end
  end
end