Sha256: b6bfca036ab58fda27fdc46d1970f7b574aef1ca5585fe2834ca1893cdaed3f2

Contents?: true

Size: 765 Bytes

Versions: 2

Compression:

Stored size: 765 Bytes

Contents

# frozen_string_literal: true

require "csv"

module MrCommon
  module PreRegistrations
    # Implements PreRegistration import for the admin panel. Expects the user to
    # upload a CSV file with a header line and columns ordered like:
    #   first_name, last_name, email
    class ImportController < BaseController
      def new
      end

      def create
        csv = import_params[:csv_file]
        importer = MrCommon::PreRegistrationImporter.new(csv.read)
        result = importer.import
        redirect_to new_pre_registrations_import_path, notice: "Imported #{result.created} and skipped #{result.skipped} duplicate or invalid entries."
      end

      def import_params
        params.require(:import).permit(:csv_file)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mr_common-2.1.0 app/controllers/mr_common/pre_registrations/import_controller.rb
mr_common-2.0.0 app/controllers/mr_common/pre_registrations/import_controller.rb