- 
      
 - 
        
Save ihatov08/828a8923dedd353abe49e5f7545529fb to your computer and use it in GitHub Desktop.  
Revisions
- 
        
stereoscott revised this gist
Oct 17, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -24,7 +24,7 @@ def index def render_csv set_csv_headers self.response_body = csv_lines end def set_csv_headers  - 
        
stereoscott revised this gist
Oct 17, 2013 . 2 changed files with 20 additions and 14 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ # if you want to monkey patch every controller, put this in initializers/active_admin.rb ActiveAdmin::ResourceController.class_eval do include ActiveAdmin::CSVStream end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,11 +1,13 @@ # put in an autoloaded path, like lib/active_admin require 'csv' module ActiveAdmin module CSVStream # using ActionController::Live breaks warden # see https://github.com/plataformatec/devise/issues/2332 # include ActionController::Live def apply_pagination(chain) chain = super unless formats.include?(:csv) @@ -22,7 +24,7 @@ def index def render_csv set_csv_headers self_response_body = csv_lines end def set_csv_headers @@ -33,17 +35,21 @@ def csv_lines default = ActiveAdmin.application.csv_options options = default.merge active_admin_config.csv_builder.options columns = active_admin_config.csv_builder.columns Enumerator.new do |y| CSV.generate(options) do |csv| y << columns.map(&:name).to_csv #response.stream.write columns.map(&:name).to_csv collection.each do |resource| row = columns.map do |column| call_method_or_proc_on resource, column.data end.to_csv y << row #response.stream.write row end end end #response.stream.close end end  - 
        
stereoscott revised this gist
Oct 15, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ # if you want to monkey patch every controller, put this in initializers/active_admin.rb class ActiveAdmin::ResourceController include ActiveAdmin::CSVStream end  - 
        
stereoscott revised this gist
Oct 15, 2013 . 3 changed files with 8 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ # if you want to monkey patch every controller, put this in initializers/active_admin.rb module ActiveAdmin::ResourceController include ActiveAdmin::CSVStream end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,6 @@ # put in an autoloaded path, like lib/active_admin require 'csv' module ActiveAdmin module CSVStream This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ #admin/users.rb to use in a single controller ActiveAdmin.register User do controller do include ActiveAdmin::CSVStream  - 
        
stereoscott revised this gist
Oct 15, 2013 . 2 changed files with 7 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ # put in an autoload path, like lib/active_admin module ActiveAdmin module CSVStream This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ #admin/users.rb ActiveAdmin.register User do controller do include ActiveAdmin::CSVStream end end  - 
        
stereoscott created this gist
Oct 15, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,48 @@ module ActiveAdmin module CSVStream include ActionController::Live def apply_pagination(chain) chain = super unless formats.include?(:csv) chain end def index index! do |format| format.csv { render_csv } end end private def render_csv set_csv_headers csv_lines end def set_csv_headers headers["Content-Type"] = "text/csv" end def csv_lines default = ActiveAdmin.application.csv_options options = default.merge active_admin_config.csv_builder.options columns = active_admin_config.csv_builder.columns CSV.generate(options) do |csv| response.stream.write columns.map(&:name).to_csv collection.each do |resource| row = columns.map do |column| call_method_or_proc_on resource, column.data end.to_csv response.stream.write row end end response.stream.close end end end