Using rubyzip error - no such file to load -- zip/zip
Asked Answered
T

7

25

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.

Thay answered 13/5, 2011 at 20:41 Comment(4)
Did you ever find a solution? I am in the same situation. ThanksKarolinekaroly
Nope i am still in search of the solution, it works in irb shell but not with rails.Thay
Make sure you have gem 'rubyzip' in your Gemfile. Also, it depends what functionality of rubyzip you're using, but you may need to use require 'zip/zipfilesystem' in addition to what you have above.Karolinekaroly
gem 'rubyzip', :require => 'zip/zip' in Gemfile worked :) Finally! Thanks ErikThay
T
22

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

Add this to your Gemfile

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

Just adding gem 'rubyzip did not work for me.

Thay answered 6/6, 2011 at 23:42 Comment(1)
did work for me after I changed to be ... :require => 'zip' in Gemfile, and in application code to require 'zip'Purify
I
23

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

gem 'rubyzip',  "~> 0.9.9"

Using rubyzip (1.0.0) caused an error. There's a note about this on 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'
Incoherent answered 5/9, 2013 at 7:27 Comment(2)
interesting how this question was asked long before the 1.0.0 was releasedIncoherent
Thank you! This helped me with the error caused when I added the gtfs gem: /home/kobilya/.rvm/gems/ruby-2.1.0/gems/gtfs-0.2.2/lib/gtfs/source.rb:3:in 'require': cannot load such file -- zip/zip (LoadError)Silver
T
22

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

Add this to your Gemfile

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

Just adding gem 'rubyzip did not work for me.

Thay answered 6/6, 2011 at 23:42 Comment(1)
did work for me after I changed to be ... :require => 'zip' in Gemfile, and in application code to require 'zip'Purify
S
17

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

gem 'zip-zip'

Saves updating legacy code.

Spooky answered 24/12, 2013 at 2:28 Comment(0)
P
7

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

https://mcmap.net/q/537942/-rails-3-loaderror-cannot-load-such-file-zip-zip

Ploss answered 21/10, 2013 at 23:7 Comment(0)
T
3

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.

Thermic answered 17/8, 2012 at 12:39 Comment(0)
T
1

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.

Tevet answered 22/5, 2012 at 15:41 Comment(0)
P
1

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:

gem 'rubyzip', :require => 'zip/zip'
Pich answered 20/6, 2013 at 9:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.