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 ?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With