0

Initially i have used zipruby gem and upgrading the rails environment and try to switch rubyzip. then what will be the equivalent of this.

Used gem in gem file - gem 'rubyzip',gem 'nokogiri',rails-4.1.9,ruby -2.2

Zip::Archive.open("#{@docx_file.path}") do |dest|
   n = dest.num_files
    n.times do |i|
      case dest.get_name(i)
        when 'word/document.xml'
          dest.replace_buffer i, @docx[:template].to_xml
       else
          #
       end
   end
end

issue -uninitialized constant Zip::Archive

1 Answers1

3

According to the README file of the rubyzip gem, the correct class to use is Zip::File. You can read a zip file by using

Zip::File.open('foo.zip') do |zip_file|
  # Handle entries one by one
  zip_file.each do |entry|
    # Extract to file/directory/symlink
    puts "Extracting #{entry.name}"
    entry.extract(dest_file)

    # Read into memory
    content = entry.get_input_stream.read
  end

  # Find specific entry
  entry = zip_file.glob('*.csv').first
  puts entry.get_input_stream.read
end

Please read the documentation available to you.

Holger Just
  • 52,918
  • 14
  • 115
  • 123
  • Out of interest, I checked older versions of the gem to see whether the API changed. But `Zip::Archive` was *never* defined by the gem. – Tom Lord Jun 22 '16 at 08:06
  • @holger it's work and i read it already but i am not getting expected result. initially i have used zipruby gem and now upgrading the environment of rails and ruby then i decide to switch rubyzip gem but face difficulties to moving. i have fully updated my method which i need to convert.please check it and give me exact solution if possible. – Arvind Rajput Jun 22 '16 at 08:18
  • 1
    @ArvindRajput The answer to your original (and changed) question is still the same. If you have an additional question, please ask a new one. Please make sure to describe exactly what your problem is in this new question. Please refer to http://stackoverflow.com/help/mcve on how to write a good question that allows people to help you. – Holger Just Jun 22 '16 at 08:39
  • @ArvindRajput If you are still having difficulties, please create a new, well structured question. As this answer shows, your syntax for using this gem is invalid - you need to read the documentation and update it appropriately. – Tom Lord Jun 22 '16 at 08:42