Pregunta

I have a rails-api project, which uses my own local gem for authorization purposes. This gem should connect MongoDB to store users and tokens.

I cannot esablish connection with MongoDB using Mongoid and doing

Mongoid.load!(yaml_dir, env)

When I call any method from Mongoid (load!, logger) I got

/Users/M/.rvm/gems/ruby-2.1.0/gems/mongoid-1.0.6/lib/mongoid.rb:68:in 'method_missing': undefined method 'load!' for #<Mongoid::Config:0x000001049e10d8> (NoMethodError)

How to connect with mongo from local gem?

¿Fue útil?

Solución 2

The solution was to specify

gem 'mongoid', github: 'mongoid/mongoid'

in gem Gemfile and

gem 'mongoid', '~>4.0.0.beta1', github: 'mongoid/mongoid'

Rails Gemfile.

gem.gemspec has to have the following entries:

spec.add_runtime_dependency 'mongoid'
spec.add_runtime_dependency 'bson'
spec.add_runtime_dependency 'bson_ext'

Otros consejos

The cause of the problem is that the method isn't supported in the version of mongoid that your are using (in your case version 1.0.6)

It appears that based on your version of rails the mongoid gem downloaded a really old version. Once you upgrade your version of rails and stick in the following into your gemfile you're problem should be solved: gem "mongoid", "~> 4.0.0.beta1"

Also, make sure to upgrade your version of mongoid once there is a stable version release (ie post-beta)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top