Unicorn triggers mongoid error during assets precompile
Asked Answered
R

2

11

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 ?

Rett answered 8/2, 2013 at 15:26 Comment(0)
C
7

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.

Cureall answered 8/2, 2013 at 15:36 Comment(3)
Odd though, I have that line commented out and it still fails this way for me.Birgitbirgitta
Apparently this is no longer supported in Rails 4.0 (it is mentioned it isn't necessary) and I seem to be getting this error.Birgitbirgitta
I'm getting this in Rails 4.0, any ideas how to fix it?Santanasantayana
B
14

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.

Birgitbirgitta answered 22/7, 2013 at 22:17 Comment(0)
C
7

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.

Cureall answered 8/2, 2013 at 15:36 Comment(3)
Odd though, I have that line commented out and it still fails this way for me.Birgitbirgitta
Apparently this is no longer supported in Rails 4.0 (it is mentioned it isn't necessary) and I seem to be getting this error.Birgitbirgitta
I'm getting this in Rails 4.0, any ideas how to fix it?Santanasantayana

© 2022 - 2024 — McMap. All rights reserved.