I'm asking this with the intention of also supplying the answer, since I had a lot of trouble figuring out what was going wrong, and Google wasn't much help - however, since this is StackOverflow, I'm sure that someone will answer it more competently or improve the answer.
I needed to upgrade a gem for a rails application that I'm working on, which introduced two new dependencies, one of which is mime-types. Working locally, I added the following line to config/environment.rb:
config.gem 'mime-types', :version => '1.17'
For deployment on our server, it's necessary for all gem dependencies to be installed in vendor/gems, so I then installed the mime-types gem into the current rvm gemset with:
gem install mime-types --version 1.17
... and unpacked a version of that into vendor/gems with:
rake gems:unpack
rake gems:unpack:dependencies
However, after deploying on the server, I found that when rake db:migrate was run, the following error appeared, indicating that the mime-types gem couldn't be found (stack trace partially elided):
no such file to load -- mime-types
/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require'
[...]
/lib/tasks/misc.rake:4
/usr/lib/ruby/1.8/rake.rb:636:in `call'
/usr/lib/ruby/1.8/rake.rb:636:in `execute'
/usr/lib/ruby/1.8/rake.rb:631:in `each'
/usr/lib/ruby/1.8/rake.rb:631:in `execute'
/usr/lib/ruby/1.8/rake.rb:597:in `invoke_with_call_chain'
/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/usr/lib/ruby/1.8/rake.rb:590:in `invoke_with_call_chain'
/usr/lib/ruby/1.8/rake.rb:607:in `invoke_prerequisites'
/usr/lib/ruby/1.8/rake.rb:604:in `each'
/usr/lib/ruby/1.8/rake.rb:604:in `invoke_prerequisites'
/usr/lib/ruby/1.8/rake.rb:596:in `invoke_with_call_chain'
/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/usr/lib/ruby/1.8/rake.rb:590:in `invoke_with_call_chain'
/usr/lib/ruby/1.8/rake.rb:583:in `invoke'
/usr/lib/ruby/1.8/rake.rb:2051:in `invoke_task'
/usr/lib/ruby/1.8/rake.rb:2029:in `top_level'
/usr/lib/ruby/1.8/rake.rb:2029:in `each'
/usr/lib/ruby/1.8/rake.rb:2029:in `top_level'
/usr/lib/ruby/1.8/rake.rb:2068:in `standard_exception_handling'
/usr/lib/ruby/1.8/rake.rb:2023:in `top_level'
/usr/lib/ruby/1.8/rake.rb:2001:in `run'
/usr/lib/ruby/1.8/rake.rb:2068:in `standard_exception_handling'
/usr/lib/ruby/1.8/rake.rb:1998:in `run'
/usr/bin/rake:28
no such file to load -- mime-types
/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require'
[...]
/lib/tasks/misc.rake:4
/usr/lib/ruby/1.8/rake.rb:636:in `call'
/usr/lib/ruby/1.8/rake.rb:636:in `execute'
/usr/lib/ruby/1.8/rake.rb:631:in `each'
/usr/lib/ruby/1.8/rake.rb:631:in `execute'
/usr/lib/ruby/1.8/rake.rb:597:in `invoke_with_call_chain'
/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/usr/lib/ruby/1.8/rake.rb:590:in `invoke_with_call_chain'
/usr/lib/ruby/1.8/rake.rb:607:in `invoke_prerequisites'
/usr/lib/ruby/1.8/rake.rb:604:in `each'
/usr/lib/ruby/1.8/rake.rb:604:in `invoke_prerequisites'
/usr/lib/ruby/1.8/rake.rb:596:in `invoke_with_call_chain'
/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/usr/lib/ruby/1.8/rake.rb:590:in `invoke_with_call_chain'
/usr/lib/ruby/1.8/rake.rb:583:in `invoke'
/usr/lib/ruby/1.8/rake.rb:2051:in `invoke_task'
/usr/lib/ruby/1.8/rake.rb:2029:in `top_level'
/usr/lib/ruby/1.8/rake.rb:2029:in `each'
/usr/lib/ruby/1.8/rake.rb:2029:in `top_level'
/usr/lib/ruby/1.8/rake.rb:2068:in `standard_exception_handling'
/usr/lib/ruby/1.8/rake.rb:2023:in `top_level'
/usr/lib/ruby/1.8/rake.rb:2001:in `run'
/usr/lib/ruby/1.8/rake.rb:2068:in `standard_exception_handling'
/usr/lib/ruby/1.8/rake.rb:1998:in `run'
/usr/bin/rake:28
Missing these required gems:
mime-types = 1.17
You're running:
ruby 1.8.7.302 at /usr/bin/ruby1.8
rubygems 1.3.7 at /home/mark/.gem/ruby/1.8, /var/lib/gems/1.8
Run `rake gems:install` to install the missing gems.
However, mime-types was present in vendor/gems/mime-types-1.17. Why doesn't rake think that the gem is installed in this case?
A colleague helpfully fixed this problem for me: it seems that Rails expects all the gems in vendor/gems to have a particular layout, which mime-types doesn't conform to. The solution is to change the line in environment.rb that specifies the dependency on mime-type to add the :lib option, which should specify a relative path that indicates how to get to the source in the gem:
config.gem 'mime-types', :version => '1.17', :lib => 'mime/types'
This means to look in vendor/gems/mime-types-1.17/lib/mime/types rather than the default based on the gem name, vendor/gems/mime-types-1.17/lib/mime-types/
just remove require 'mime-types' in your ruby file.
as mime-types is built in ruby. you don't need to install its gem or include its explicitly.
just use it. this works for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With