NoMethodError: undefined method `[]‘ for nil:NilClass error on heroku

It’s been a while since I’ve updated my app on heroku. In between the mongoid version updated and configuration file (mongoid.yml) did change. That for me was the most obvious change, but then as well, there were a couple of things under the hood, that only showed up once I tried to deploy on heroku. The above error appeared and left me clueless for a moment, until I figured out, I had to define the ruby version 1.9.3 in my Gemfile:

source 'http://rubygems.org'

ruby '1.9.3'

gem 'rails', '~>3.2'

gem 'jquery-rails'
gem 'mongoid'

This change made the error disappear. For some more background information see Mongoid Tips, this blog post on heroku and this Stackoverflow post.

For who is interested, the new mongoid.yml looks like this in my project:



# set these environment variables on your prod server
production:
  sessions:
    default:
      uri: <%= ENV['MONGOLAB_URL'] %>
      options:
        skip_version_check: true
        safe: true

Related Posts

No Comments

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment