Module: ElaineCrud::ExportHandling
- Extended by:
- ActiveSupport::Concern
- Included in:
- BaseController
- Defined in:
- lib/elaine_crud/export_handling.rb
Overview
Handles data export functionality (CSV, Excel, JSON) Provides export action and format generation methods
Instance Method Summary collapse
-
#export ⇒ Object
Export records in CSV, Excel (XLSX), or JSON format Respects current search/filter state and enforces max export limits.
Instance Method Details
#export ⇒ Object
Export records in CSV, Excel (XLSX), or JSON format Respects current search/filter state and enforces max export limits
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/elaine_crud/export_handling.rb', line 14 def export # Fetch records without pagination for export @records = fetch_records_for_export # Check record count if @records.count > self.class.max_export_records redirect_to polymorphic_path(crud_model), alert: "Cannot export more than #{self.class.max_export_records} records. Please apply filters to reduce the number of records.", status: :see_other return end @columns = determine_columns @model_name = crud_model.name respond_to do |format| format.csv do send_data generate_csv(@records, @columns), filename: export_filename('csv'), type: 'text/csv', disposition: 'attachment' end format.xlsx do send_data generate_xlsx(@records, @columns), filename: export_filename('xlsx'), type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', disposition: 'attachment' end format.json do render json: generate_json(@records, @columns), status: :ok end end end |