1

我正在尝试将这个 gem,https: //github.com/charlotte-ruby/impressionist 改编为mongoid odm。

我在https://github.com/tute/impressionist/commit/1c3f809da8ebd3ced8cb9bda8caee89012091a10中看到了mongo_mapper的提交。

这是 mongoid 的印象.rb 模型:

class Impression
  include Mongoid::Document
  include Mongoid::Timestamps::Created
  field :impressionable_type, :type => String
  field :impressionable_id, :type => String
  field :user_id, :type => String
  field :controller_name, :type => String
  field :action_name, :type => String
  field :view_name, :type => String
  field :request_hash, :type => String
  field :ip_address, :type => String
  field :session_hash, :type => String
  field :message, :type => String
  field :referrer, :type => String
end

生成 mongoid 文件后:

rails g impressionist --orm mongo_id
      invoke  mongo_id
      create  config/initializers/impression.rb

我尝试运行服务器并收到此错误:

uninitialized constant Impressionist::Engine::MongoId (NameError)
    from /home/ubuntu/.rvm/gems/ruby-1.9.3-p125@rails32/gems/impressionist-1.1.1/lib/impressionist/engine.rb:11:in `block in <class:Engine>'

engine.rb文件中我有:

require "impressionist"
require "rails"

module Impressionist
  class Engine < Rails::Engine
    initializer 'impressionist.model' do |app|
      require "#{root}/app/models/impressionist/impressionable.rb"
      if Impressionist.orm == :mongo_id
        require "impressionist/models/mongo_id/impression.rb"
        require "impressionist/models/mongo_id/impressionist/impressionable.rb"
        MongoId::Document.plugin Impressionist::Impressionable
      end
    end

    initializer 'impressionist.controller' do
      ActiveSupport.on_load(:action_controller) do
        include ImpressionistController::InstanceMethods
        extend ImpressionistController::ClassMethods
      end
    end
  end
end

第 11 行是MongoId::Document.plugin Impressionist::Impressionable

任何人都可以帮忙吗?谢谢

4

1 回答 1

2

在第 11 行

MongoId::Document.plugin Impressionist::Impressionable

应该

Mongoid::Document.plugin Impressionist::Impressionable

注意 的大小写Mongoid

于 2012-07-06T17:50:26.473 回答