使用 ruby​​zip 错误 - 没有要加载的文件 - zip/zip

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5997539/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 01:07:46  来源:igfitidea点击:

Using rubyzip error - no such file to load -- zip/zip

ruby-on-railsruby-on-rails-3rubygemsrubyzip

提问by coredump

I know there is another thread on this subject but I still face this problem even after using all solutions. Is there any other way to generate zip files? Can i use Ubuntu system commands?

我知道关于这个主题还有另一个线程,但即使使用了所有解决方案,我仍然面临这个问题。还有其他方法可以生成zip文件吗?我可以使用 Ubuntu 系统命令吗?

I did

我做了

 gem install rubyzip

I have

我有

require 'rubygems'
require 'zip/zip'

in my controller

在我的控制器中

But i still get the same error - no such file to load -- zip/zip I tried with both ruby 1.8.7 and ruby 1.9.2 with rails 3.0.5 on Ubuntu

但我仍然遇到同样的错误 - 没有这样的文件可以加载 - 我在 Ubuntu 上尝试使用 ruby​​ 1.8.7 和 ruby​​ 1.9.2 以及 rails 3.0.5 的 zip/zip

Could you please help me? Thanks.

请你帮助我好吗?谢谢。

采纳答案by coredump

After spending lot of time, I finally figured out the missing part. When using the rubyzipgem, I also had to require zip/zip.

花了很多时间后,我终于找到了缺失的部分。使用rubyzipgem 时,我还必须要求zip/zip.

Add this to your Gemfile

将此添加到您的 Gemfile

gem 'rubyzip', :require => 'zip/zip'

gem 'rubyzip', :require => 'zip/zip'

Just adding gem 'rubyzipdid not work for me.

只是添加gem 'rubyzip对我不起作用。

回答by eagor

I fixed this problem by specifying gem version 0.9.9 in Gemfile:

我通过在 Gemfile 中指定 gem 版本 0.9.9 解决了这个问题:

gem 'rubyzip',  "~> 0.9.9"

Using rubyzip (1.0.0) caused an error. There's a note about this on rubyzip gihub:

使用 ruby​​zip (1.0.0) 导致错误。在rubyzip gihub上有一个关于这个的说明:

Rubyzip interface changed!!! No need to do require "zip/zip" and Zip prefix in class names removed. If you have issues with any third-party gems what required rubyzip you can use next temporary fix:

# Place this line before your library or on the head of your Gemfile
gem 'rubyzip', '< 1.0.0'

Rubyzip 界面改变了!!!不需要删除类名中的“zip/zip”和 Zip 前缀。如果您对任何需要 ruby​​zip 的第三方 gem 有问题,您可以使用下一个临时修复:

# Place this line before your library or on the head of your Gemfile
gem 'rubyzip', '< 1.0.0'

回答by Zubin

Building on @eagor's answer, if you'd like to use rubyzip >= 1.0 but need backwards compatibility add this to your Gemfile:

基于@eagor 的回答,如果您想使用 ruby​​zip >= 1.0 但需要向后兼容,请将其添加到您的 Gemfile 中:

gem 'zip-zip'

Saves updating legacy code.

保存更新遗留代码。

回答by mmell

When upgrading rubyzip to 1.0.0 change require 'zip/zip'to require 'zip'.

将 ruby​​zip 升级到 1.0.0 时更改require 'zip/zip'require 'zip'.

https://stackoverflow.com/a/19506372/567399

https://stackoverflow.com/a/19506372/567399

回答by Chris Shanks

Also make sure that your unzipping process uses:

还要确保您的解压缩过程使用:

Zip::ZipFile.open(self.data) do |zipfile|

not

不是

Zip::Zipfile.open(self.data) do |zipfile|

The capital F on ZipFile makes a difference.

ZipFile 上的大写 F 有所不同。

回答by Artur Ma?ecki

In my case I was needed to change from

就我而言,我需要从

Zip::File.open(...)

to

Zip::ZipFile.open(...)

of course I need to also add this to Gemfile:

当然,我还需要将其添加到 Gemfile 中:

gem 'rubyzip', :require => 'zip/zip'

回答by Alex D

For anyone else who has problems with rubyzipand comes across this thread: remember that you can always shell out to an external command-line zip utility. There are a number of free command-line utilities which you can find through Google. Once you install your command-line zip program of choice and make sure it is on the system path, just use backticks to drive it from within Ruby. Of course, this won't work for web applications which are running on Heroku, etc.

对于rubyzip遇到此线程问题并遇到此线程的任何其他人:请记住,您始终可以使用外部命令行 zip 实用程序。您可以通过 Google 找到许多免费的命令行实用程序。一旦你安装了你选择的命令行 zip 程序并确保它在系统路径上,只需使用反引号从 Ruby 中驱动它。当然,这不适用于在 Heroku 等上运行的 Web 应用程序。