如何将 mongoid 集成到 Ruby on Rails 和 Windows 中

发布于 2024-12-22 21:40:31 字数 2496 浏览 0 评论 0原文

ruby 版本是 1.9.2p290

我使用以下 gemset

D:\work\software\mongoid>gem list

* LOCAL GEMS *

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_adapters/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 version is 1.9.2p290

I am using the following gemset

D:\work\software\mongoid>gem list

* LOCAL GEMS *

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)

when I run rake db:migrate, I am getting the error

Please install the mongo adapter: gem install activerecord-mongo-adapter (no s
uch file to load -- active_record/connection_adapters/mongo_adapter)

when trying to install activerecord-mongo-adapter, I am getting the error

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

database.yml contains the following code...,

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你げ笑在眉眼 2024-12-29 21:40:31

Mongoid 不是 ActiveRecord 适配器

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

因此,除了不将 mongo 内容放入 database.yml 之外,您的模型看起来

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

像是继承自 ActiveRecord::Base

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

Mongoid isn't an ActiveRecord adapter

If you want to use mongoid then you don't need to use ActiveRecord at all (unless of course you also have a SQL database your app uses). If you don't need active record then you'll probably need to disable the active record framework entirely or else it will probably complain about not being able to connect.

So in addition to not putting mongo stuff in database.yml, your models look like

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

rather than inheriting from ActiveRecord::Base

It also means no Activerecord migrations etc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文