Rails 3: How to create a compressed file on demand

How to generate compressed files on demand.

I have this controller

def create send_data generate_tgz("#{RAILS_ROOT}/tmp/example.txt"), :filename => 'export.tgz' end 

But this gives me a method that is not found on generate_tgz.

Is it a plugin or a gem? Do I need to demand something? Can I generate a zip file instead?

Edit:

 def generate_tgz(file) system("tar -czf #{RAILS_ROOT}/tmp/export-result #{RAILS_ROOT}/tmp/export") content = File.read("#{RAILS_ROOT}/tmp/export-result") #ActiveSupport::Gzip.compress(content) end 

This creates tgz, but when I unpack it, I get app / c3ec2057-7d3a-40d9-9a9d-d5c3fe3ffd6f / home / tmp / export / and_the_files

I would just like: export / the_files

+6
ruby-on-rails
source share
1 answer

The method does not exist. You can easily create it using ActiveSupport :: Gzip .

 def generate_tgz(file) content = File.read(file) ActiveSupport::Gzip.compress(content) end 
+3
source share

All Articles