Cyril Duchon-Doris
Cyril Duchon-Doris

Reputation: 14039

mongoid uninitialized constant Point

I hear about and try to implement those libraries mongoid-geospatial

But they all mention this class Point which is undefined for me. What am I missing ?

I am adding a geo concern to my models with ActiveSupport::Concern

module Mappable
  extend ActiveSupport::Concern

  included do
    include Mongoid::Geospatial

    field :coordinates, type: Point, spatial: true
    spatial_scope :coordinates

uninitialized constant Mappable::Point (NameError)

Upvotes: 0

Views: 331

Answers (1)

max
max

Reputation: 102368

You need to resolve it from the proper namespace.

field :coordinates, type: ::Mongoid::Geospatial::Point, spatial: true

The example from the docs works since they are declaring a class which does not create a new module nesting. In your case however Ruby will try to resolve Point from the current module (Mapping) even if you have included Mongoid::Geospatial.

Upvotes: 2

Related Questions