Sha256: 70d5a0c7077b77ccad426ac6a52ac2ca7577b254d88a696bb19e4a147cb5e379

Contents?: true

Size: 451 Bytes

Versions: 6

Compression:

Stored size: 451 Bytes

Contents

Mime::Type.register 'application/zip', :zip

class ActionController::Responder
  def to_zip
    name = "#{controller.resource.class.name.downcase}_#{Time.now.to_i}"
    controller.send(:end_of_association_chain).pg_copy_to "/tmp/#{name}.csv"
    Dir.chdir('/tmp') do
     `zip #{name} #{name}.csv`
     zip = "#{name}.zip"
     return controller.send_file zip, :filename => zip, :type => "application/zip", :disposition => 'inline'
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
postgres-copy-0.5.3 lib/postgres-copy/zip_responder.rb
postgres-copy-0.5.2 lib/postgres-copy/zip_responder.rb
postgres-copy-0.5.0 lib/postgres-copy/zip_responder.rb
postgres-copy-0.4.0 lib/postgres-copy/zip_responder.rb
postgres-copy-0.3.6 lib/postgres-copy/zip_responder.rb
activerecord-postgres-copy-0.3.6 lib/postgres-copy/zip_responder.rb