suweller / mongoid-autoinc

⬆ Auto incrementing fields for Mongoid documents
MIT License
62 stars 44 forks source link

Issue with Mongoid 5 #29

Closed Veejay closed 8 years ago

Veejay commented 8 years ago

Hi,

I switched to mongoid-autoinc due to an upgrade to mongoid 5.0.2 (was using proton/mongoid_auto_increment) before. Using this issue to thank everyone involved for providing an alternative that is well supported by newer versions of Mongoid 👍

Context

It's a rails 4.2.0 application. Here's what I specified in the Gemfile:

gem 'mongoid', '~> 5.0.0'
gem 'mongoid-autoinc', '~> 5.0.0'

The Gemfile.lock file after a bundle install has the following versions locked:

mongoid (5.0.2)
    activemodel (~> 4.0)
    mongo (~> 2.1)
    origin (~> 2.1)
    tzinfo (>= 0.3.37)
mongoid-autoinc (5.0.2)
    mongoid (~> 5.0)

Excerpt from the model:

class Page
  include Mongoid::Document
  include Mongoid::Autoinc
  ...SNIP...
  increments :_small_id, seed: 0

Error

The error I'm getting in the Rails logs is the following:

NameError (uninitialized constant Mongoid::Autoinc):

I am starting the server with bundle exec rails server and I did bundle install so I would expect Mongoid::Autoinc to be defined.

Veejay commented 8 years ago

My bad, the documentation does specify the need for

require autoinc

I thought it was for standalone applications and wasn't needed for Rails. It is. Once I added it to my model, it worked fine. Closing this.