简体   繁体   English

使用rubyzip错误 - 没有这样的文件加载 - zip / zip

[英]Using rubyzip error - no such file to load — zip/zip

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? 有没有其他方法来生成zip文件? Can i use Ubuntu system commands? 我可以使用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 但我仍然得到相同的错误 - 没有这样的文件加载 - zip / zip我尝试使用ruby 1.8.7和ruby 1.9.2与rails 3.0.5在Ubuntu

Could you please help me? 请你帮助我好吗? Thanks. 谢谢。

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. 使用rubyzip(1.0.0)导致错误。 There's a note about this on rubyzip gihub : rubyzip gihub上有一个关于这个的说明:

Rubyzip interface changed!!! Rubyzip界面改变了! No need to do require "zip/zip" and Zip prefix in class names removed. 无需执行“zip / zip”和删除类名中的Zip前缀。 If you have issues with any third-party gems what required rubyzip you can use next temporary fix: 如果您对任何第三方宝石有疑问,需要使用rubyzip,您可以使用下一个临时修复:

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

After spending lot of time, I finally figured out the missing part. 花了很多时间后,我终于找到了缺失的部分。 When using the rubyzip gem, I also had to require zip/zip . 使用rubyzip宝石时,我还需要zip/zip

Add this to your Gemfile 将其添加到您的Gemfile中

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

Just adding gem 'rubyzip did not work for me. 只是添加gem 'rubyzip对我来说不起作用。

Building on @eagor's answer, if you'd like to use rubyzip >= 1.0 but need backwards compatibility add this to your Gemfile: 建立@ eagor的答案,如果您想使用rubyzip> = 1.0但需要向后兼容,请将此添加到您的Gemfile:

gem 'zip-zip'

Saves updating legacy code. 保存更新遗留代码。

When upgrading rubyzip to 1.0.0 change require 'zip/zip' to require 'zip' . 将rubyzip升级到1.0.0时require 'zip/zip'require 'zip'

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

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有所不同。

For anyone else who has problems with rubyzip and comes across this thread: remember that you can always shell out to an external command-line zip utility. 对于任何遇到rubyzip问题并遇到此线程的人:请记住,您始终可以使用外部命令行zip实用程序。 There are a number of free command-line utilities which you can find through Google. 您可以通过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. 一旦你安装了你选择的命令行zip程序并确保它在系统路径上,只需使用反引号从Ruby中驱动它。 Of course, this won't work for web applications which are running on Heroku, etc. 当然,这不适用于在Heroku上运行的Web应用程序等。

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'

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

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