Unicorn triggers mongoid error during assets precompile

☆樱花仙子☆ 提交于 2019-12-03 18:01:39

问题


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'

The full stacktrace can be found at http://pastebin.com/8YcJHEmS

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

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 ?


回答1:


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.




回答2:


As I recently had this problem with Rails 4.0 and config.assets.initialize_on_precompile = false no longer has any effect with Rails 4.0 I spoke with Heroku support and was told to use this labs feature:

heroku labs:enable user-env-compile

I wasn't able to get an answer as to why the user environment is necessary only with Unicorn but it seems to be a Unicorn specific problem of some sort or Thin does something that prevents the entire app from booting.

The whole thing seems odd to me and smells of a problem with the way assets are pre-compiled.



来源:https://stackoverflow.com/questions/14775844/unicorn-triggers-mongoid-error-during-assets-precompile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!