rails 3 - LoadError (cannot load such file -- zip/zip)
Asked Answered
B

8

16

I'm using rubyzip to zip a csv file so uses can download it. This works perfectly in development mode. But when I tried zipping the file on the production server (rackspace) I received the error: LoadError (cannot load such file -- zip/zip). Is it a path issue? Anyone know a fix?

The error is being called in my code on this line: require 'zip/zip'

I've tried the solution from here, but it didn't help.

Bukharin answered 22/8, 2012 at 18:33 Comment(1)
Not related with this question but in case someone will have the same problem as me - with versions > 1.0 you should require 'zip' not 'zip/zip'Unearth
B
5

I had the same problem: error thrown on "require 'zip/zip'" code, and the solution from this post also did not help.

After a long research I found that the problem was that my "require 'zip/zip'" statement was done in a separate

lib/exporters/package_exporter.rb

file, and for some reason "require" statements are not handled in "lib" folder in production by default.

When I moved "require 'zip/zip'" to the beginning of my

app/controllers/packages_controller.rb

the problem was solved!

Bushwhack answered 29/11, 2012 at 13:6 Comment(1)
Can you show me an example? I'm having the same problem and can't fix it at all.Wonderwork
E
31

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.

Eri answered 5/9, 2013 at 7:26 Comment(1)
Or you can also add gem 'zip-zip' which provides backward compatibility.Swear
S
20

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

Stormie answered 21/10, 2013 at 23:6 Comment(1)
I think this is the winnerParegoric
D
8

I had this problem after adding roo to a Rails project.

Roo needed the new interface, something else (some other gem) was using the old interface - so most of these answers didn't work (couldn't lower the version of rubyzip, rubyzip2 is deprecated, didn't have require zip/zip in my project).

What worked for me was cassio-s-cabral's answer referring to the rubyzip github page.

gem 'rubyzip', '>= 1.0.0' # will load new rubyzip version
gem 'zip-zip' # will load compatibility for old rubyzip API.
Dogleg answered 27/4, 2015 at 3:12 Comment(0)
B
5

I had the same problem: error thrown on "require 'zip/zip'" code, and the solution from this post also did not help.

After a long research I found that the problem was that my "require 'zip/zip'" statement was done in a separate

lib/exporters/package_exporter.rb

file, and for some reason "require" statements are not handled in "lib" folder in production by default.

When I moved "require 'zip/zip'" to the beginning of my

app/controllers/packages_controller.rb

the problem was solved!

Bushwhack answered 29/11, 2012 at 13:6 Comment(1)
Can you show me an example? I'm having the same problem and can't fix it at all.Wonderwork
S
5

I had a similar issue with active_support, just added the 'zip' gem to my Gemfile and it worked fine

Sapid answered 30/8, 2013 at 16:0 Comment(0)
F
2

I'm use rubyzip2 gem to fix this problem

gem 'rubyzip2'
Flak answered 30/1, 2015 at 9:42 Comment(0)
L
2

what work for me was to install 2 gems:
gem install rubyzip gem install zip and in the script put
require 'rubygems' require 'zip/zip'

Lila answered 14/8, 2015 at 23:20 Comment(0)
D
0

In their github page explains what to do.

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 old version of rubyzip you can use next workaround:

gem 'rubyzip', '>= 1.0.0' # will load new rubyzip version
gem 'zip-zip' # will load compatibility for old rubyzip API.
Douceur answered 12/12, 2014 at 14:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.