export_controller_concern.rb 564 B

1234567891011121314151617181920212223242526272829303132
  1. # frozen_string_literal: true
  2. module ExportControllerConcern
  3. extend ActiveSupport::Concern
  4. included do
  5. before_action :authenticate_user!
  6. before_action :load_export
  7. skip_before_action :require_functional!
  8. end
  9. private
  10. def load_export
  11. @export = Export.new(current_account)
  12. end
  13. def send_export_file
  14. respond_to do |format|
  15. format.csv { send_data export_data, filename: export_filename }
  16. end
  17. end
  18. def export_data
  19. raise 'Override in controller'
  20. end
  21. def export_filename
  22. "#{controller_name}.csv"
  23. end
  24. end