简体   繁体   English

未初始化的常量Zip :: Archive

[英]uninitialized constant Zip::Archive

Initially i have used zipruby gem and upgrading the rails environment and try to switch rubyzip. 最初,我使用zipruby gem并升级了Rails环境,并尝试切换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 gem文件中的二手gem-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 问题-未初始化的常量Zip :: Archive

According to the README file of the rubyzip gem, the correct class to use is Zip::File . 根据rubyzip gem的README文件 ,正确使用的类是Zip::File You can read a zip file by using 您可以使用读取zip文件

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. 请阅读可用的文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM