Rails Engine + Mongoid: No configuration could be found for a session named 'default'

你。 提交于 2019-12-03 03:02:32

you probably missed require 'rails/mongoid' in your spec_helper.rb file.

Had someone having the same issue in here https://github.com/mongoid/mongoid/issues/2894#issuecomment-14903927

Try adding that require, that should fix it.

This is probably because of two simultaneous conditions: ( there is no production section in mongoid.yml ) AND ( Heroku treats Rails applications as production by default ).

Fixing either one shall suffice.

1. There is no production section in mongoid.yml

Add production section to mongoid.yml, as explained at Heroku , e.g.

production:
  sessions:
    default:
      uri: <%= ENV['MONGOHQ_URL'] %>
      options:
        skip_version_check: true
        safe: true

2. Heroku treats rails applications as production by default

Set Heroku environment to development, or a add a new environment which would be specific to Heroku, as explained at Heroku, e.g.

heroku config:set RACK_ENV=development RAILS_ENV=development --remote development

This worked for me on my machine

1: Add this to your config/application.rb

Mongoid.load!("path to your mongoid.yml")

2: And change your mongoid.yml from (Only for mongoid version < 5):

This

development:
  clients:
    default:
      database: database_for_development
        hosts:
          - localhost:27017
test:
  clients:
    default:
      database: database_for_test
        hosts:
          - localhost:27017
production:
  clients:
    default:
      database: database_for_production
        hosts:
          - localhost:27017

To:

development:
  sessions:
    default:
      database: database_for_development
        hosts:
          - localhost:27017
test:
  sessions:
    default:
      database: database_for_test
        hosts:
          - localhost:27017
production:
  sessions:
    default:
      database: database_for_production
        hosts:
          - localhost:27017

And restart the server after making changes to mongoid.yml

I've found this working - notice there is no "sessions", only "clients"

production:
  clients:
    default:
      uri: <%= ENV['MONGODB_URI'] %>
      options:
        skip_version_check: true
        safe: true
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!