简体   繁体   English

Mongoid未初始化常数点

[英]mongoid uninitialized constant Point

I hear about and try to implement those libraries mongoid-geospatial 我听说并尝试实现那些库mongoid-geospatial

But they all mention this class Point which is undefined for me. 但是他们都提到了该类Point ,这对我来说是未定义的。 What am I missing ? 我想念什么?

I am adding a geo concern to my models with ActiveSupport::Concern 我正在使用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) 未初始化的常量Mappable :: Point(NameError)

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 . 但是,在您的情况下,即使您包含Mongoid::Geospatial Ruby也会尝试从当前模块( Mapping )解析Point

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM