gpt4 book ai didi

ruby-on-rails - 为什么找不到 mime 类型的 gem(在 vendor/gems 中解压)?

转载 作者:行者123 更新时间:2023-12-04 06:26:31 24 4
gpt4 key购买 nike

我问这个问题也是为了提供答案,因为我在弄清楚出了什么问题时遇到了很多麻烦,而且 Google 也帮不上什么忙 - 然而,由于这是 StackOverflow,我确定有人会更胜任地回答或改进答案。

我需要为我正在处理的 Rails 应用程序升级一个 gem,它引入了两个新的依赖项,其中之一是 mime-types。在本地工作,我将以下行添加到 config/environment.rb:

config.gem 'mime-types', :version => '1.17'

为了在我们的服务器上部署,所有 gem 依赖项都必须安装在 vendor/gems 中,所以我随后将 mime-types gem 安装到当前的 rvm 中 gem 镶嵌:

gem install mime-types --version 1.17

... 并将它的一个版本解压到 vendor/gems 中:

rake gems:unpack
rake gems:unpack:dependencies

但是部署到服务器后,发现在运行rake db:migrate时,出现如下错误,说明mime-types gem不能'找不到(堆栈跟踪部分省略):

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 不认为在这种情况下安装了 gem?

最佳答案

一位同事帮我解决了这个问题:Rails 似乎希望 vendor/gems 中的所有 gem 都有特定的布局,而 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 而不是基于 gem 名称的默认值 vendor/gems/mime-types -1.17/lib/mime-types/

关于ruby-on-rails - 为什么找不到 mime 类型的 gem(在 vendor/gems 中解压)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11249396/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com