Sha256: ba5bb1fd840c35224615c725efe46e69e7f4afce0cc49d534432b42367849b96

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

module RailsImporter
  class ImportsController < ::ApplicationController
    before_filter :set_importer_class

    def new
      @import = Import.new(importer_key: @importer_class.key)
    end

    def create
      @import = Import.new(import_params)
      if @import.valid?
        ImportJob.perform_later @import.importer_key, @import.filepath
        flash[:notice] = I18n.t(:processing_import, scope: :rails_importer)
        redirect_to after_import_path
      else
        render 'new'
      end
    end

    def sample
      file = File.open(@importer_class.sample_file)

      send_data file.read, :filename => File.basename(@importer_class.sample_file)
    rescue => e
      flash[:alert] = I18n.t(:sample_file_not_available, scope: :rails_importer)
      redirect_to after_import_path
    end

    private

    def set_importer_class
      @importer_class = RailsImporter.importer_class(params[:importer_key].to_s)
      if @importer_class.nil?
        flash[:error] = I18n.t(:importer_does_not_exist, scope: :rails_importer)
        redirect_to after_import_path
      end
    end

    def import_params
      params.require(:import).permit(:importer_key, :import_file)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rails_importer-0.2.0 app/controllers/rails_importer/imports_controller.rb