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 Controller

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

Methods included from Config

#exhibit_specific_blacklight_config

Instance Method Details

#createObject



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

def create
  file = csv_params[:url]
  csv = CSV.parse(file.read, headers: true, return_headers: false, encoding: 'utf-8').map(&:to_hash)
  Spotlight::AddUploadsFromCSV.perform_later(csv, current_exhibit, current_user)
  flash[:notice] = t('spotlight.resources.upload.csv.success', file_name: file.original_filename)
  redirect_to :back
end

#templateObject



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

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