将印象派宝石改编为mongoid

时间:2012-07-06 15:55:47

标签: ruby-on-rails gem mongoid

我正在尝试将此宝石https://github.com/charlotte-ruby/impressionist改为 mongoid odm。

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

这是mongoid的impression.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 fine文件后:

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

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

1 个答案:

答案 0 :(得分:2)

第11行

MongoId::Document.plugin Impressionist::Impressionable

应该是

Mongoid::Document.plugin Impressionist::Impressionable

请注意Mongoid

的大小写