ActiveScaffold :: Wiki
Csv Export Action Plugin

Csv Export Action Plugin

Overview

This is the export code originally posted by Samsam that has been repackaged as an Active Scaffold plugin with more configuration options and a FasterCSV implementation (which can be easily overridden)

Even if you don’t need CSV export capability, this plugin is a useful example of how to override and extend Active Scaffold.

Features

Installation

For the latest functionality, you’ll need a version of Active Scaffold 1.1 (currently trunk revision 582 or later) and the current trunk version of the activescaffoldexport plugin:

svn export http://activescaffold.googlecode.com/svn/trunk/ vendor/plugins/active_scaffold
svn checkout http://activescaffoldexport.googlecode.com/svn/trunk/ vendor/plugins/activescaffoldexport

If you need Active Scaffold 1.0.1 compatibility, use this activescaffoldexport branch instead:

svn checkout http://activescaffoldexport.googlecode.com/svn/branches/AS_1.0.1_compatible/ vendor/plugins/activescaffoldexport
note: This version is currently localized in French and does not have RESTful routing support. Hopefully this will change soon. :)

A Rails 2.1 + Active Scaffold edge-compatible version is available from Git Hub.

Usage

Add the export action to your controller

  active_scaffold :people do |c|
    c.actions.add :export
    c.export.columns = [ :id, :name, :birth_date ]
    c.export.default_deselected_columns = [ :birth_date ]
    c.export.default_delimiter = ';'
    c.export.force_quotes = true
  end

To add the export action to all your controllers, and set application-wide defaults, you can add a block to your application.rb file:

  ActiveScaffold.set_defaults do |c|
    c.actions.add :export
    c.export_force_quotes = true
  end

Note the use of export_force_quotes instead of export.force_quotes, take a look at lib/config/core.rb where the Active Scaffold::Config level instance variables are defined.