Class: Spotlight::Resources::CsvUploadController

Inherits:
ApplicationController show all
Defined in:
app/controllers/spotlight/resources/csv_upload_controller.rb

Overview

Creating new exhibit items from single-item entry forms or batch CSV upload

Instance Method Summary collapse

Methods included from Concerns::ApplicationController

#enabled_in_spotlight_view_type_configuration?, #field_enabled?

Methods included from Controller

#blacklight_config, #current_exhibit, #current_masthead, #current_masthead=, #current_site, #default_url_options, #exhibit_masthead?, #exhibit_search_action_url, #exhibit_search_facet_url, #resource_masthead?, #search_action_url, #search_facet_url, #set_exhibit_locale_scope, #set_locale

Methods included from Config

#exhibit_specific_blacklight_config

Instance Method Details

#createObject



17
18
19
20
21
22
# File 'app/controllers/spotlight/resources/csv_upload_controller.rb', line 17

def create
  csv = CSV.parse(csv_io_param, headers: true, return_headers: false).map(&:to_hash)
  Spotlight::AddUploadsFromCSV.perform_later(csv, current_exhibit, current_user)
  flash[:notice] = t('spotlight.resources.upload.csv.success', file_name: csv_io_name)
  redirect_to spotlight.admin_exhibit_catalog_path(current_exhibit)
end

#templateObject



24
25
26
# File 'app/controllers/spotlight/resources/csv_upload_controller.rb', line 24

def template
  render plain: CSV.generate { |csv| csv << data_param_keys.unshift(:url) }, content_type: 'text/csv'
end