I followed the official tutorial.Не удается получить мангоидную работу с рельсами 4
Я sqlite3 заметил в моей Gemfile, а также следующие строки:
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? Замена содержимого базы данных.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.
Да, у меня есть. Однако, если я изменю его на mongoid, у меня есть файл конфигурации mongoid.yml и файл конфигурации database.yml, и я не уверен, как поменять местами два. –
В конце учебника, которое вы связали, они говорили о том, как удалить database.yml, не так ли? – revolver