使用 rubyzip 错误 - 没有要加载的文件 - zip/zip
我知道关于这个主题还有另一个线程,但即使在使用所有解决方案后我仍然面临这个问题。还有其他方法可以生成 zip 文件吗?我可以使用 Ubuntu 系统命令吗?
有
gem install rubyzip
我
require 'rubygems'
require 'zip/zip'
的控制器中
但我仍然遇到相同的错误 - 没有要加载的文件 - zip/zip 我在 Ubuntu 上尝试了 ruby 1.8.7 和 ruby 1.9.2 以及 Rails 3.0.5
你能帮我吗?谢谢。
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?
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
Could you please help me? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我通过在 Gemfile 中指定 gem 版本 0.9.9 解决了这个问题:
使用 rubyzip (1.0.0) 导致错误。 rubyzip gihub 上有关于此的注释:
I fixed this problem by specifying gem version 0.9.9 in Gemfile:
Using rubyzip (1.0.0) caused an error. There's a note about this on rubyzip gihub:
花了很多时间,我终于弄清楚了缺失的部分。当使用
rubyzip
gem时,我还必须要求zip/zip
。将其添加到您的 Gemfile
gem 'rubyzip', :require => 'zip/zip'
仅添加
gem 'rubyzip
对我来说不起作用。After spending lot of time, I finally figured out the missing part. When using the
rubyzip
gem, I also had to requirezip/zip
.Add this to your Gemfile
gem 'rubyzip', :require => 'zip/zip'
Just adding
gem 'rubyzip
did not work for me.基于 @eagor 的答案,如果您想使用 rubyzip >= 1.0 但需要向后兼容性,请将其添加到您的 Gemfile 中:
保存更新遗留代码。
Building on @eagor's answer, if you'd like to use rubyzip >= 1.0 but need backwards compatibility add this to your Gemfile:
Saves updating legacy code.
将 rubyzip 升级到 1.0.0 时,将
require 'zip/zip'
更改为require 'zip'
。https://stackoverflow.com/a/19506372/567399
When upgrading rubyzip to 1.0.0 change
require 'zip/zip'
torequire 'zip'
.https://stackoverflow.com/a/19506372/567399
还要确保您的解压缩过程使用:
而不是
ZipFile 上的大写 F 会有所不同。
Also make sure that your unzipping process uses:
not
The capital F on ZipFile makes a difference.
对于任何遇到
rubyzip
问题并遇到此线程的人:请记住,您始终可以使用外部命令行 zip 实用程序。您可以通过 Google 找到许多免费的命令行实用程序。安装所选的命令行 zip 程序并确保它位于系统路径上后,只需使用反引号从 Ruby 中驱动它即可。当然,这不适用于在 Heroku 等上运行的 Web 应用程序。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. 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.就我而言,我需要从 更改为
当然
,我还需要将其添加到 Gemfile 中:
In my case I was needed to change from
to
of course I need to also add this to Gemfile: