【发布时间】:2013-03-24 22:25:50
【问题描述】:
我遇到了一个问题,即捆绑器没有在 Rails 应用程序中加载单个 gem,而只是在生产中加载 - 在开发模式下使用 gem 没有问题。
gem 是 country_select,我们已经在 1.1.3 版和 github 存储库中进行了尝试。该应用正在使用 rails 3.2.11。
gem 存在于服务器上的证明
bundler 在生产环境中成功安装gem:
$ RAILS_ENV=production bundle install
...
Using coffee-rails (3.2.2)
Using country_select (1.1.3)
Using daemons (1.1.9)
...
Your bundle is complete! It was installed into /home/deploy/rails-app/shared/bundle
gem 出现在 bundler 安装到的共享 gem 目录中:
$ ls -al /home/deploy/rails-app/shared/bundle/ruby/1.9.1/gems/ | grep country
drwxrwxr-x 3 deploy deploy 4096 Apr 3 08:49 country_select-1.1.3
从控制台启动rails时会加载gem:
$ RAILS_ENV=production script/rails c
Loading production environment (Rails 3.2.11)
irb(main):002:0> Gem.loaded_specs.keys.grep /country/
=> ["country_select"]
但是……
在 rails 应用程序中对 country_select gem 的相同检查失败。例如:
class ApplicationController < ActionController::Base
before_filter do
raise Gem.loaded_specs.keys.grep(/country/).inspect
end
#...
end
吐出[] - 即未加载gem。此外,依赖 gem 的部分应用程序由于它不存在而失败。
最后,问题
只需在启动中的某处添加require 'country_select' 就意味着 gem 被加载,并且应用程序可以运行。但是为什么 bundler 不使用那个特定的 gem,尽管它会安装它并将它添加到应用程序的 gem 目录中?
更多关于生产环境的信息:
$ rvm -v
rvm 1.18.18 (stable)...
$ ruby -v
ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-linux]
$ gem -v
1.8.25
$ bundle -v
Bundler version 1.3.2
更新:2013 年 4 月 5 日
问题似乎已经“消失”了。经过几次重新部署后,它似乎正在工作。尽管 country_select gem 没有改变,这非常很奇怪。我仍在调查那段时间到底发生了什么变化,但我很困惑。
【问题讨论】:
-
你能把我们链接到你的 Gemfile 吗?
-
@RyanAngilly 当然,here's the Gemfile
-
我总是在启动时将 require 放在我的代码中 - 这不是常见的做法吗?
-
@lightswitch05 rails 3 在 config/application.rb 中使用 bundler 时默认执行此操作。但如果不使用 bundler 或更早的 rails 版本,则需要它。
-
我遇到了这个问题,它在生产中将我的 Rails 应用程序置于仅 500 模式...你有没有做任何事情让它消失?还是捆绑器在几天后才开始工作?
标签: ruby-on-rails ruby gem bundler