无法让 mongoid 与 Rails 4 一起使用

2024-04-22

我是按照官方教程来的 http://mongoid.org/en/mongoid/docs/installation.html.

我在 Gemfile 中注释掉了 sqlite3 以及以下几行:

gem 'mongoid', '~> 4', github: 'mongoid/mongoid'
gem 'bson_ext'

然而,我不断收到Specified 'sqlite3' for database adapter, but the gem is not loaded. Add gem "sqlite3" to your Gemfile.

原因似乎是database.yml 仍然将sqlite 列为数据库。我该如何让 Rails 使用生成的 mongoid.yml ?用 mongoid.yml 替换 database.yml 的内容似乎并不能解决问题 - 我明白了

ActiveRecord::AdapterNotSpecified: database configuration does not specify adapter error.

它与 Rails 4 不兼容还是我错过了一些简单的东西?

编辑:我想我变暖了。我已将适配器添加为“mongoid”。现在这是我的database.yml 的内容:

development:
  adapter: 'mongoid'
  # Configure available database sessions. (required)
  sessions:
    # Defines the default session. (required)
    default:
      # Defines the name of the default database that Mongoid can connect to.
      # (required).
      database: xboxie
      # Provides the hosts the default session can connect to. Must be an array
      # of host:port pairs. (required)
      hosts:
        - localhost:27017
      options:
        # Change whether the session persists in safe mode by default.
        # (default: false)
        # safe: false

        # Change the default consistency model to :eventual or :strong.
        # :eventual will send reads to secondaries, :strong sends everything
        # to master. (default: :eventual)
        # consistency: :eventual

        # How many times Moped should attempt to retry an operation after
        # failure. (default: 30)
        # max_retries: 30

        # The time in seconds that Moped should wait before retrying an
        # operation on failure. (default: 1)
        # retry_interval: 1
  # Configure Mongoid specific options. (optional)
  options:
    #
test:
  sessions:
    default:
      database: xboxie_test
      hosts:
        - localhost:27017
      options:
        consistency: :strong
        # In the test environment we lower the retries and retry interval to
        # low amounts for fast failures.
        max_retries: 1
        retry_interval: 0


# # SQLite version 3.x
# #   gem install sqlite3
# #
# #   Ensure the SQLite 3 gem is defined in your Gemfile
# #   gem 'sqlite3'
# development:
#   adapter: sqlite3
#   database: db/development.sqlite3
#   pool: 5
#   timeout: 5000

# # Warning: The database defined as "test" will be erased and
# # re-generated from your development database when you run "rake".
# # Do not set this db to the same as development or production.
# test:
#   adapter: sqlite3
#   database: db/test.sqlite3
#   pool: 5
#   timeout: 5000

# production:
#   adapter: sqlite3
#   database: db/production.sqlite3
#   pool: 5
#   timeout: 5000

产生错误:

LoadError: Could not load 'active_record/connection_adapters/mongoid_adapter'. Make sure that the adapter in config/database.yml is valid. If you use an adapter other than 'mysql', 'mysql2', 'postgresql' or 'sqlite3' add the necessary adapter gem to the Gemfile.


我通过添加解决了这个问题:

Mongoid.load!(Rails.root.join("/config/mongoid.yml"))

to config/intializers/mongoid.rb,按照教程。

此外,您还需要更改 config/application.rb 文件中的以下行:

require 'rails/all'

到(在 Rails 3.x 中):

require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "rails/test_unit/railtie"
# require "sprockets/railtie" # Uncomment this line for Rails 3.1+

或(在 Rails 4.x 中):

# Pick the frameworks you want:
# require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "sprockets/railtie"
require "rails/test_unit/railtie"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法让 mongoid 与 Rails 4 一起使用 的相关文章

随机推荐

  • 获取特定时区的当前时间

    我有一个具有不同时区的日期和时间格式的数据框 我想将其与该时区的当前时间进行比较 所以我想在下面的 日期和时间 列中添加 1 小时 然后将其与该时区的当前时间进行比较 就像第一个一样 时区是 EDT 当前时间是 2017 07 18 10
  • Java 枚举和 Switch 语句 - 默认情况?

    对于建议抛出异常的人 抛出异常不会给我带来编译时错误 它会给我带来运行时错误 我知道我可以抛出异常 我宁愿在编译期间死也不愿在运行时死 首先 我使用的是 eclipse 3 4 我有一个数据模型 其模式属性是枚举 enum Mode on
  • Windows 上的异步子进程

    首先 我要解决的总体问题比我在这里展示的要复杂一些 所以请不要告诉我 使用阻塞线程 因为如果没有公平 公平的重写 它就无法解决我的实际情况重构 我有几个不需要我修改的应用程序 它们从标准输入获取数据 并在发挥其魔力后将其输出到标准输出 我的
  • WordPress 树枝模板短代码不显示

    我在 Wordpress 中使用 Symfony Twig 模板 一切运行良好 除了我无法在页面模板中显示任何短代码 我正在尝试使用 Contact form 7 插件显示联系表单 短代码是这样的 contact form 7 id 123
  • 无法让 Karaf 4.2.6 使用 log4j2 和 JsonLayout 作为布局类型进行日志记录

    我一整天都在做这件事 但在尝试了这么多组合后却没有让它发挥作用 归根结底 我正在寻找从 Karaf 获取 JSON 日志记录的明确步骤列表 我什至浏览了 Maven Karaf 插件源代码 试图解决这个问题 尽管也许我看的还不够远 我正在使
  • 将特定选定的列提取到新的 DataFrame 作为副本

    我有一个包含 4 列的 pandas DataFrame 我想创建一个new数据框only有三列 这个问题类似于 从数据框中提取特定列 https stackoverflow com questions 10085806 extractin
  • 使用导航组件设置 BottomNavView 后,Jetpack Compose TopAppBar 闪烁

    使用 Jetpack Compose 应用程序进行工作BottomNavigationView和导航组件 我对活动内的底部栏进行了常规设置 val navHostFragment supportFragmentManager findFra
  • SQL Server 更新分组依据

    我尝试在 MS SQL 上执行此操作 但仅在 Group by line 处返回错误 update temp Set Dos Count 1 From Temp Table2010 s where Id s Total and s tota
  • 在 php 中上传文件大小 > 5MB 时出错?

    我上传的文件大小 gt 5MB 和配置php ini 但是当上传文件是结果时error File Error size ini 如何配置 还有另一个配置条目会影响此行为 post max size
  • Windows 服务恢复未重新启动服务

    我将 Windows 服务的恢复配置为在失败后延迟一分钟重新启动 但我从未真正重新启动服务 即使有最明显的错误 我确实在事件查看器中收到一条消息 无法在源 MyApp exe 中找到事件 ID 1 的描述 本地计算机可能没有必要的注册表信息
  • pip install ortools:没有匹配的发行版 - Alpine

    在 Docker 中 我尝试运行 pip install ortools 但找不到 其他 pip 安装包可以完美运行 我在 Dockerfile 中使用 FROM python 3 6 8 alpine bash 4 4 pip insta
  • 实体框架:获取存储库中的子类对象

    我有与下面列出的数据库表对应的以下模型 经理就是雇员 会计师也是雇员 让所有管理器都进入存储库的最佳方法是什么 如何实现GetAllManagers 方法 这是正确的TPT吗 CODE MyRepository MyEmployeeRepo
  • schema.org 产品可用性标签标记

    哪一个是正确的 span span 我检查了官方模式文档 并在示例中找到了所有这些 我想它们都可以 但目前有什么首选标准吗 Using span与content属性是invalid HTML5 和 Microdata 都不允许content
  • Amazon S3 静态网站不提供 css 或 js 文件

    我一直在尝试在 Amazon S3 上建立一个静态网站 我已经设置好使用我的个人域 到目前为止我已经能够很好地访问内容 所有链接都有效 无论是 根 目录中的页面还是子文件夹中的页面 因此 S3 似乎可以遵循我正在使用的路径 问题是没有任何
  • 根据另一个数据库的查询结果查询一个数据库

    我在 VS 2013 中使用 SSIS 我需要从 1 个数据库获取 ID 列表 并使用该 ID 列表 我想查询另一个数据库 即SELECT from MySecondDB WHERE ID IN list of IDs from MyFir
  • 扩展 Three.js 类

    我想扩展 Three js Object3D 类 但不知道该怎么做 有一个 Stackoverflow 问题 我已经阅读 重新阅读和尝试过 但无法让它为我工作 有没有办法扩展 ThreeJS 对象 https stackoverflow c
  • Xcode 服务:选择 Git 分支

    我开始在 Mavericks 中设置新的 Xcode 服务 我创建了一个新的机器人 但没有询问我它应该构建的分支 如何为每个机器人选择分支 我不仅想建造master 但也有不同的分支 在当前版本中 当您在 Xcode 中创建机器人时 它将链
  • 如何将音乐播放器保留在页脚中,当我单击子页面的链接时,该音乐播放器不会重新加载?

    我已经尝试解决这个问题有一段时间了 并且浏览了许多论坛来寻找解决方案 这是我的设置 任何帮助将不胜感激 我目前有一个索引页 在 内容 部分的上方和下方加载 JavaScript 页眉和页脚 我在标题内还有一个导航链接列表 我的音乐播放器位于
  • 将向量::emplace_back与shared_ptr一起使用

    include
  • 无法让 mongoid 与 Rails 4 一起使用

    我是按照官方教程来的 http mongoid org en mongoid docs installation html 我在 Gemfile 中注释掉了 sqlite3 以及以下几行 gem mongoid gt 4 github mo