activeadmin-plugins / active_admin_import

:paperclip: active_admin_import is based on activerecord-import gem - the most efficient way to import for ActiveAdmin
http://activeadmin-plugins.github.io/active_admin_import
MIT License
183 stars 101 forks source link

need possibility to wrap whole process inside transaction #169

Open senid231 opened 4 years ago

senid231 commented 4 years ago

also it will be nice to have ability to pass template_object as proc

Fivell commented 4 years ago

current solution

      active_admin_import options

      controller do
        around_action :wrap_in_transaction, only: [:do_import]

        def wrap_in_transaction
          ApplicationRecord.transaction do
            yield
            # When error appears during ActiveAdminImport process
            # it's being rescued inside gem and adds flash error.
            # In this case we must rollback a transaction.
            # see https://github.com/activeadmin-plugins/active_admin_import/issues/169
            raise ActiveRecord::Rollback if flash[:error].present?
          end
        end