【问题标题】:How to integrate mongoid in ruby on rails with windows如何将 mongoid 集成到 ruby​​ on rails with windows
【发布时间】:2011-12-22 03:22:14
【问题描述】:

ruby 版本是 1.9.2p290

我正在使用以下 gemset

D:\work\software\mongoid>宝石列表

* 本地宝石 *

abstract (1.0.0)
actionmailer (3.1.3, 3.1.0, 3.0.1)
actionpack (3.1.3, 3.1.0, 3.0.1)
activemodel (3.1.3, 3.1.0, 3.0.1)
activerecord (3.1.3, 3.1.0, 3.0.1)
activerecord-alt-mongo-adapter (0.1.0)
activerecord-sqlserver-adapter (3.1.0.0)
activeresource (3.1.3, 3.1.0, 3.0.1)
activesupport (3.1.3, 3.1.0, 3.0.1)
ansi (1.4.1)
arel (2.2.1, 1.0.1)
bcrypt-ruby (3.0.1 x86-mingw32, 3.0.0 x86-mingw32)
bson (1.5.2, 1.1.1)
bson_ext (1.5.2, 1.1.1)
builder (3.0.0, 2.1.2)
bundler (1.0.18)
coffee-rails (3.1.1, 3.1.0)
coffee-script (2.2.0)
coffee-script-source (1.2.0, 1.1.3, 1.1.2)
erubis (2.7.0, 2.6.6)
execjs (1.2.13, 1.2.12, 1.2.4)
hike (1.2.1)
i18n (0.6.0, 0.4.2)
jquery-rails (1.0.19)
json (1.6.3)
mail (2.3.0, 2.2.19, 2.2.9)
mime-types (1.17.2, 1.16)
minitest (2.9.1, 1.6.0)
mongo (1.5.2, 1.0.9)
mongo_mapper (0.10.1)
mongodb (2.1.0)
mongoid (2.3.4, 2.0.0.beta.19)
multi_json (1.0.4, 1.0.3)
open4 (1.1.0)
pg (0.11.0 x86-mingw32)
Platform (0.4.0)
plucky (0.4.3)
polyglot (0.3.3, 0.3.2, 0.3.1)
POpen4 (0.1.4)
rack (1.3.5, 1.3.2, 1.2.4, 1.2.1)
rack-cache (1.1, 1.0.3)
rack-mount (0.8.3, 0.6.14, 0.6.13)
rack-ssl (1.3.2)
rack-test (0.6.1, 0.5.7, 0.5.6)
rails (3.1.3, 3.1.0, 3.0.1)
railties (3.1.3, 3.1.0, 3.0.1)
rake (0.9.2.2, 0.9.2, 0.8.7)
rb-readline (0.4.1)
rdoc (3.12, 3.9.4)
rubygems-update (1.8.12)
rubyzip2 (2.0.1)
sass (3.1.12, 3.1.11)
sass-rails (3.1.5)
sprockets (2.0.3)
sqlite3 (1.3.5 x86-mingw32, 1.3.4 x86-mingw32)
sqlite3-ruby (1.3.3, 1.2.5 x86-mingw32)
thor (0.14.6, 0.14.3)
tilt (1.3.3)
tiny_tds (0.4.5 x86-mingw32)
treetop (1.4.10, 1.4.8)
turn (0.8.3, 0.8.2)
tzinfo (0.3.31, 0.3.29, 0.3.23)
uglifier (1.2.0)
will_paginate (3.0.2, 3.0.pre2)

当我运行 rake db:migrate 时,我收到了错误

请安装 mongo 适配器:gem install activerecord-mongo-adapter(没有 要加载的 uch 文件 -- active_record/connection_adapter/mongo_adapter)

在尝试安装 activerecord-mongo-adapter 时,出现错误

ERROR:  Could not find a valid gem 'activerecord-mongo-adapter' (>= 0) in any re
pository

database.yml 包含以下代码...,

development:
      adapter:  mongo
      host:     localhost
      port:     27017
      database: mongo_development

test:
  adapter: mongo
  database: mongo_test
  host: localhost

production:
  adapter: mongo
  database: mongo_production
  host: localhost

【问题讨论】:

    标签: ruby-on-rails mongoid jruby


    【解决方案1】:

    Mongoid 不是 ActiveRecord 适配器

    如果您想使用 mongoid,那么您根本不需要使用 ActiveRecord(当然,除非您的应用程序也有一个 SQL 数据库)。如果您不需要活动记录,那么您可能需要完全禁用活动记录框架,否则它可能会抱怨无法连接。

    所以除了不把 mongo 的东西放在 database.yml 中之外,你的模型看起来像

    class Person
      include Mongoid::Document
      ...
      end
    end
    

    而不是从ActiveRecord::Base继承

    这也意味着没有 Activerecord 迁移等。

    【讨论】:

    • 最初提出问题的人试图编辑您的帖子并要求提供更多信息。他们的编辑已被拒绝,因为他们应该发表评论,但您可以阅读他们试图询问的内容 here
    猜你喜欢
    • 2015-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-18
    • 2012-10-14
    • 2015-09-05
    • 2013-04-10
    • 2020-10-02
    相关资源
    最近更新 更多