我问这个也是为了提供答案,因为我在弄清楚出了什么问题时遇到了很多麻烦,谷歌没有多大帮助 - 但是,因为这是StackOverflow,我我相信有人会更有能力地回答这个问题或者改善答案。
我需要为我正在处理的rails应用程序升级gem,它引入了两个新的依赖项,其中一个是mime-types
。在本地工作,我将以下行添加到config/environment.rb
:
config.gem 'mime-types', :version => '1.17'
要在我们的服务器上进行部署,必须在vendor/gems
中安装所有gem依赖项,然后我将mime-types
gem安装到当前的rvm gemset中:
gem install mime-types --version 1.17
...并将其版本解压缩到vendor/gems
,其中包含:
rake gems:unpack
rake gems:unpack:dependencies
但是,在服务器上部署之后,我发现当运行rake db:migrate
时,出现以下错误,表示找不到mime-types
gem(堆栈跟踪部分省略):< / p>
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.
但mime-types
中存在vendor/gems/mime-types-1.17
。为什么rake不认为在这种情况下安装了宝石?
答案 0 :(得分:4)
一位同事帮我解决了这个问题:似乎Rails希望vendor/gems
中的所有宝石都有一个特定的布局,mime-types
不符合。解决方案是更改environment.rb
中指定依赖mime-type
的行以添加:lib
选项,该选项应指定一个相对路径,指示如何到达gem中的源:
config.gem 'mime-types', :version => '1.17', :lib => 'mime/types'
这意味着根据宝石名称vendor/gems/mime-types-1.17/lib/mime/types
vendor/gems/mime-types-1.17/lib/mime-types/
而不是默认值
答案 1 :(得分:1)
只需删除ruby文件中的require 'mime-types'
。
因为mime-types
是用ruby构建的。您不需要安装其gem或明确包含它。
只需使用它。 这适合我。