13

公式のチュートリアルに従いました

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 がまだリストされているためと思われます。生成された mongoid.yml を Rails で使用するにはどうすればよいですか? database.yml のコンテンツを mongoid.yml に置き換えてもうまくいかないようです。

ActiveRecord::AdapterNotSpecified: database configuration does not specify adapterエラー。

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.

4

6 に答える 6

13

以下を追加してこれを解決しました:

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

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"
于 2013-07-23T02:29:37.410 に答える
8

同様の問題がありました。ActiveRecordなしでアプリを再作成することですべて解決しました...

rails new app_name --skip-active-record

上記のように Gem を追加し、mongoid.yml を正しく取得します...

于 2013-09-22T13:23:31.300 に答える
2

この問題は、mongo を使用しているときに発生します。基本的にモンゴはアクティブレコードと相性が悪い。したがって、コマンドを使用してアプリケーションを生成します。

rails g myApp --skip-active-record

私の場合はうまくいきます

于 2016-03-03T16:33:36.197 に答える