Class: ExportManager::ExportManagerController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- ExportManager::ExportManagerController
- Defined in:
- app/controllers/export_manager/export_manager_controller.rb
Instance Method Summary collapse
Instance Method Details
#download ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/controllers/export_manager/export_manager_controller.rb', line 27 def download begin request_params = params.except("action", "controller", "table", "select-all", "type") model_name = params["table"].singularize.camelize columns = request_params.keys records = model_name.constantize.all export_data(records, columns, @file_name) rescue => e redirect_to export_path logger.error "Error generating CSV: #{e.message}" flash[:error] = "An error occurred while generating the CSV file - #{e.message}" end end |
#export ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/controllers/export_manager/export_manager_controller.rb', line 5 def export remove_table = defined?(REMOVE_TABLE_NAME) ? REMOVE_TABLE_NAME : [] @model_name = ActiveRecord::Base.connection.tables.map do |t| next if remove_table.include?(t.downcase) formatted_name = t.gsub("_", " ").titleize.gsub(" ", "") [ formatted_name, t ] end.compact if remove_table.present? @model_name.delete_if { |item| remove_table.any? { |target| item.include?(target) } } end @model_name end |
#send_coloum_name ⇒ Object
22 23 24 25 |
# File 'app/controllers/export_manager/export_manager_controller.rb', line 22 def send_coloum_name columns = ActiveRecord::Base.connection.columns(params["table"]).map(&:name) render json: columns end |