Skip to content

naaano/active_scaffold_export

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Active Scaffold Export

An active scaffold addon to let it export data in CSV or XLSX format

####How to? Easy. First get active scaffold if you haven't yet. Then, add this to your Gemfile:

gem 'active_scaffold_export'

if you're using REE or Ruby 1.8.7, you need to add backports gem as well as fastercsv since REE lacks ruby 1.9 streaming features and fastercsv is in core in 1.9

gem 'backports'
gem 'fastercsv'

if you want xlsx format, add:

gem 'axlsx_rails'

if that gem is present, XLSX will be used by default. You can change this by adding to active scaffold config:

conf.export.default_file_format = 'csv' # or 'xlsx' 

read important notes at the bottom about xlsx.

Remember to bundle install. Add to application.css:

 *= require active_scaffold_export

Now let's add it to controller, inside active_scaffold config block:

conf.actions.add :export
# you can filter or sort columns if you want
conf.export.columns = %w(name last_name phone address) 
# you can define a default values for the exporting form
conf.export.default_deselected_columns = %w(phone address)
conf.export.default_delimiter = ";"
conf.export.force_quotes = "true"

And enjoy happy exporting :)

Security

It's controlled the same way as Active Scaffold. The extra actions added are:

  • :show_export for the options form
  • :export for retrieving the data Tested with AS internal security and Cancan

Translations

Go in the same active scaffold scope:

active_scaffold:
    columns_for_export: Columnas para exportar
    export_options: Opciones de exportación
    this_page: esta página
    all_pages: todas las páginas 

XLSX support

This support depends on axlsx_rails and axlsx of course. header styling override will be added soon. NOTE: There's NO streaming support for xlsx format. Only CSV. So if your data is huge, set default_file_format to 'csv' instead. Streaming in xlsx will never be supported since the entire file needs to be serialized and zipped to be a valid OOXML file. So, rather than streaming, background jobs will be the most likely future approach.
Read axlsx issue about this

This gem has not been tested in other rubies than REE and Ruby 1.9. For contact, help, support, comments, please use Active Scaffold official mailing list activescaffold@googlegroups.com

About

Export from active_scaffold with Rails 3

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 78.4%
  • HTML 20.4%
  • CSS 1.2%