Class: CsvImportMagic::ImportersController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/csv_import_magic/importers_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



10
11
12
13
14
15
16
17
18
# File 'app/controllers/csv_import_magic/importers_controller.rb', line 10

def create
  @importer = ::Importer.new(importer_params)

  if @importer.save! && import_file_csv
    redirect_to edit_importer_path(@importer), alert: t('csv_import_magic.importers_controller.create.alert')
  end
rescue ActiveRecord::RecordInvalid, CSV::MalformedCSVError => e
  redirect_back fallback_location: '/', flash: { error: e.message }
end

#editObject



20
21
22
# File 'app/controllers/csv_import_magic/importers_controller.rb', line 20

def edit
  @importer = ::Importer.find(params[:id])
end

#showObject



6
7
8
# File 'app/controllers/csv_import_magic/importers_controller.rb', line 6

def show
  @importer = ::Importer.find(params[:id])
end

#updateObject



24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/csv_import_magic/importers_controller.rb', line 24

def update
  @importer = ::Importer.find(params[:id])

  if @importer.update(csv_importer_magic_update_params)
    CsvImportMagic::ImporterWorker.perform_async(importer_id: @importer.id, resources: resources)
    redirect_to importer_path(@importer), flash: { notice: t('csv_import_magic.importers_controller.update.notice') }
  else
    errors = @importer.errors.full_messages.to_sentence
    flash[:alert] = errors.present? ? errors : t('csv_import_magic.importers_controller.update.alert')
    render :edit
  end
end