Unicorn 在资产预编译期间触发 mongoid 错误 [英] Unicorn triggers mongoid error during assets precompile

查看:40
本文介绍了Unicorn 在资产预编译期间触发 mongoid 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在 Heroku 上运行的使用 Mongoid 3 的 rails 应用程序.我刚刚更新它以使用 Unicorn.当我尝试将其部署到 Heroku 时,出现以下错误:

I have a rails app using Mongoid 3 running on Heroku. I've just updated it to use Unicorn. When I try to deploy it to Heroku I get the following error :

Running: rake assets:precompile
rake aborted!
   undefined method `match' for nil:NilClass
   /tmp/build_3nnbzpfmnjpns/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.21/lib/mongoid/sessions/mongo_uri.rb:49:in `initialize'

可以在 http://pastebin.com/8YcJHEmS

但是如果我从 Gemfile 中删除 Unicorn,则资产编译成功.查看 Mongoid 代码,我可以看到错误发生在 mongoid.yml 文件被解析时,但我无法弄清楚为什么 Unicorn 会导致它失败.我的 mongoid.yml 文件如下所示:

But if I remove Unicorn from my Gemfile, the assets compilation succeeds. Looking into the Mongoid code, I can see that the error happens when the mongoid.yml file is getting parsed, but I can't figure out why Unicorn would cause that to fail. My mongoid.yml file looks like this :

production:
  sessions:
    default:
      uri: <%= ENV['MONGOHQ_URL'] %>
      options:
        skip_version_check: true
        safe: true

还有我的 Gemfile :

And my Gemfile :

source 'https://rubygems.org'
ruby '1.9.3'

gem 'rails', '3.2.11'
gem 'thin'

group :assets do
  gem 'sass-rails',   '~> 3.2'
  gem 'coffee-rails', '~> 3.2'
  gem 'uglifier', '>= 1.0.3'
  gem "twitter-bootstrap-rails", '>=2.1.8'
  gem "bootstrap_form"

end

gem "jquery-rails"
gem 'jquery-ui-rails', "3.0.1"

gem 'newrelic_rpm'
gem "httparty"
gem "resque"
gem "resque-loner"
gem "unicorn", "4.4.0"
gem "mongoid", "~> 3.0.0"
gem "mongo", "~> 1.7.0"
gem "bson", "~> 1.7"
gem "bson_ext", "~> 1.7"
gem 'less-rails', "~> 2.2"
gem 'therubyracer', '>= 0.11.1'
gem 'libv8', '~> 3.11.8'
gem 'devise', '~> 2.1.2'
gem 'devise_invitable', '~> 1.0.0'
gem 'bootstrap_form'
gem 'font-awesome-rails'
gem 'omniauth'
gem 'omniauth-facebook'
gem 'kaminari'
gem 'mongoid_search'

你知道这是什么原因造成的吗?

Would you have any idea what's causing this ?

推荐答案

Rails 3:

在预编译资产时尝试关闭应用初始化:

Try to turn off app initialization when pre-compiling assets:

# config/application.rb
config.assets.initialize_on_precompile = false

该行应该已经被注释掉了.

The line should already be there commented out.

这篇关于Unicorn 在资产预编译期间触发 mongoid 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆