imports_controller.rb 590 B

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