ActiveScaffold Export adds an Export action to your ActiveScaffold controllers. Users can choose the columns to include and download either the current page or all matching records. The plugin preserves the list’s current filters and sorting.

CSV export works out of the box and streams large result sets in batches. XLSX export is available when caxlsx_rails is installed.

Requirements

  • Active Scaffold 4.4.0 or newer for ActiveScaffold Export 3.12
  • A Ruby and Rails version supported by the selected Active Scaffold version

Installation

Add the plugin to your Gemfile:

gem 'active_scaffold_export'

To also export Excel-compatible .xlsx files, add:

gem 'caxlsx_rails'

Install the gems:

bundle install

Enable exporting

Add the :export action inside the controller’s active_scaffold block. You can also select the available columns and choose which ones are initially deselected in the export form:

class ProductsController < ApplicationController
  active_scaffold :product do |conf|
    conf.actions.add :export
    conf.export.columns = %w[name category price created_at]
    conf.export.default_deselected_columns = %w[created_at]
  end
end

By default, the Export link opens a form where the user can:

  • select the columns to export;
  • export the current page or all matching records;
  • include or omit the header row;
  • change the CSV delimiter; and
  • choose CSV or XLSX when XLSX support is installed.

Configuration

Configure the export action inside the same active_scaffold block:

conf.export.show_form = true
conf.export.allow_full_download = true
conf.export.default_full_download = true
conf.export.default_file_format = 'csv'
conf.export.default_delimiter = ';'
conf.export.default_skip_header = false
conf.export.force_quotes = true
conf.export.draggable = false
Setting Purpose Default
columns Columns available for export The action’s default columns
default_deselected_columns Columns initially unchecked in the form None
show_form Show the options form before downloading true
allow_full_download Let users choose between the current page and all results true
default_full_download Select all matching records by default true
default_file_format Initial format: 'csv' or 'xlsx' XLSX when available; otherwise CSV
default_delimiter CSV column separator ','
default_skip_header Omit the header row by default false
force_quotes Quote every field in CSV output false
draggable Let users drag selected columns into export order false

Set show_form to false to download immediately using the configured defaults. Set allow_full_download to false to prevent users from changing the default_full_download choice.

UI adapter support

ActiveScaffold Export 3.12 renders its form with ActiveScaffold 4.4’s standard fields_container, form_element, and form_attribute elements. It adds two plugin-specific elements for the option controls:

  • export_option wraps one option.
  • export_option_row groups related options.

For example, an adapter can style the options without replacing the export form partial:

ActiveScaffold.add_element_attributes :export_option,
                                      class: "form-check"
ActiveScaffold.add_element_attributes :export_option_row,
                                      class: "d-flex gap-3"

Adapter attributes are merged with the plugin’s default classes. See Customizing UI Markup and Integrating CSS Frameworks for the complete adapter API.

Customize exported values

Define a helper named <column>_export_column to customize a column’s exported value. The helper receives the record and selected format:

def price_export_column(record, format)
  value = record.price.to_f
  return value unless format == :xlsx

  [value, { format_code: '$#,##0.00' }]
end

For XLSX, an override may return [value, style_options] to apply caxlsx formatting. You can also configure XLSX options directly on a column:

conf.columns[:price].export_options = {
  xlsx: { format_code: '$#,##0.00', width: 14 }
}

Header labels can be changed by overriding format_export_column_header_name. The helper overrides documentation describes the other formatting hooks.

XLSX notes

XLSX support requires caxlsx_rails. When it is installed, XLSX becomes the default format unless you set default_file_format to 'csv'.

Unlike CSV, XLSX output cannot be streamed: the complete workbook must be serialized and zipped before it is downloaded. Use CSV for very large exports.

The worksheet name comes from the ActiveScaffold label. Forbidden characters are replaced with -, and the result is limited to Excel’s 31-character maximum. Override worksheet_name in the controller to customize it:

def worksheet_name(options = {})
  super replace: '_', omission: ''
end

See Cell Format Options for XLSX styling details.

Authorization

Export uses ActiveScaffold’s read authorization by default. The plugin adds two controller actions:

  • show_export displays the options form;
  • export generates the download.

Override export_authorized? when an application needs a more restrictive rule. show_export_authorized? delegates to it by default.

Grouped field-search results can also be exported. In this mode, the plugin exports the grouped columns and calculated list columns instead of the normal export column set. Column overrides use the <column>_grouped_export_column naming convention.

For every available option, see the Export Configuration reference.

Get Plugin