imports_controller.rb 637 B

12345678910111213141516171819202122232425262728293031323334
  1. # frozen_string_literal: true
  2. class Settings::ImportsController < Settings::BaseController
  3. layout 'admin'
  4. before_action :authenticate_user!
  5. before_action :set_account
  6. def show
  7. @import = Import.new
  8. end
  9. def create
  10. @import = Import.new(import_params)
  11. @import.account = @account
  12. if @import.save
  13. ImportWorker.perform_async(@import.id)
  14. redirect_to settings_import_path, notice: I18n.t('imports.success')
  15. else
  16. render :show
  17. end
  18. end
  19. private
  20. def set_account
  21. @account = current_user.account
  22. end
  23. def import_params
  24. params.require(:import).permit(:data, :type)
  25. end
  26. end