2017-03-13 13 views
1

Rails 5でMongoDBを設定しようとしています。Clouditeを使用しています。私はそれにいくつか問題があります。私はMongoDBをインストールしてそれを私のgemファイルに追加しました。Rails 5とMongoDB:データベースアダプタ用に 'sqlite3'が指定されていますが、gemがロードされていません

私は

rails g mongoid:config 

を実行すると、私はエラーを取得する:ここで

Specified 'sqlite3' for database adapter, but the gem is not loaded. Add gem 'sqlite3' to your Gemfile (and ensure its version is at the minimum required by ActiveRecord)

は、私がどのように再書き込み、このためにはよく分からないdatabase.ymlの

# SQLite version 3.x 
# gem install sqlite3 
# 
# Ensure the SQLite 3 gem is defined in your Gemfile 
# gem 'sqlite3' 
# 
default: &default 
    adapter: sqlite3 
    pool: 5 
    timeout: 5000 

development: 
    <<: *default 
    database: db/development.sqlite3 

# 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: 
    <<: *default 
    database: db/test.sqlite3 

production: 
    <<: *default 
    database: db/production.sqlite3 

ですMongoDB?私はあなたがこれを行うことが、私はまたのActiveRecordを削除したり、無効にする必要がありますが、私はRailsの5に

答えて

1

生成されたアプリケーションを削除して、オプションを使用して新しいレールアプリケーションを生成します。

rails new your-project --skip-active-record 

次に、Gemfileにmongoアダプターなどを追加します。

+0

私は生成されたアプリを削除しようとしましたが、Cloud9ではあまりうまく動かないようです。私は端末からファイルを削除しました(ファイルツリー経由ではできません)。それはもうターミナルにはありませんが、私はそれをリフレッシュした後でもファイルツリーに残っています。私が新しいアプリケーションを作成したとき、それはファイルツリーにも表示されませんでした。私は、既存のアプリケーションからActiveRecordを削除する方が良いと思う。 – xeno7

+0

実際には、ワークスペースフォルダ自体ではなく、ワークスペースフォルダのすべての内容を削除するだけです。これはうまくいくはずです。 – xeno7

0

これを行う方法がわからないと思う:

database.ymlの

development: &global_settings 
    database: textual_development 
    host: 127.0.0.1 
    port: 27017 

test: 
    database: textual_test 
    <<: *global_settings 

production: 
    host: hostname 
    database: databasename 
    username: username 
    password: password 
    <<: *global_settings 

その後mongo.rb

mongo.rb

と呼ばれる設定/初期化子で初期化子を作成します0
MongoMapper.setup(Rails.configuration.database_configuration, Rails.env, :logger => Rails.logger) 

お楽しみください!

関連する問題