2013-03-12 1 views
9

레일 마운트 가능한 앱을 만들고 'mongoid'및 'rspec'보석을 추가했습니다. spec_helper.rb 모든 정상적인 작동에 나는 Mongoid.load!(Rails.root.join("config", "mongoid.yml")) 라인을 추가하면Rails Engine + Mongoid : 'default'라는 세션에 대한 구성을 찾지 못했습니다.

Mongoid::Errors::NoSessionConfig: 
Problem: 
    No configuration could be found for a session named 'default'. 
Summary: 
    When attempting to create the new session, Mongoid could not find a session configuration for the name: 'default'. This is necessary in order to know the host, port, and options needed to connect. 
Resolution: 
    Double check your mongoid.yml to make sure under the sessions key that a configuration exists for 'default'. If you have set the configuration programatically, ensure that 'default' exists in the configuration hash. 

: 내 사양을 실행하려고하면 지금 나는 다음과 같은 오류가 발생합니다.

왜로드 기능을 호출 할 필요가없는 일반 Rails 앱에서와 같은 기능을 사용할 수 있습니까?

mongoid.yml

development: 
    sessions: 
    default: 
     database: dummy_development 
     hosts: 
     - localhost:27017 
     options: 
    options: 
test: 
    sessions: 
    default: 
     database: dummy_test 
     hosts: 
     - localhost:27017 
     options: 
     consistency: :strong 
     max_retries: 1 
     retry_interval: 0 

버전 :

gem 'rails', '~> 3.2.12' 
gem 'mongoid', '~> 3.1' 
gem 'rspec-rails', '~> 2.13' 
+0

당신은 당신의 mongoid.yml 파일을 게시 할 수 있습니까? –

답변

19

당신은 아마 당신의 spec_helper.rb 파일에 require 'rails/mongoid'을 놓쳤다.

누군가가 그것을 수정해야한다고 여기 https://github.com/mongoid/mongoid/issues/2894#issuecomment-14903927

한번에 요구하는 추가에 같은 문제가 발생했다.

+0

어디에서'spec_helper.rb' 파일을 찾을 수 있습니까? –

+0

mongoid + 레일즈 용'Echo' 샘플 프로젝트에서 발견되었고, 생성 된 앱 폴더에'spec' 폴더가 없었습니다 –

+2

rspec에 의해 spec_helper.rb가 생성되었습니다. rspec을 사용하지 않는다면 넣으십시오. 귀하의 application.rb에 –

2

그리고 이것은 아마도 때문에 두 개의 동시 조건이다

4

mongoid.yml을 변경 한 후에 서버를 다시 시작 (mongoid.yml에는 생산 섹션이 없음) AND (Heroku가 기본적으로 생산으로 레일 응용 프로그램을 처리합니다) .

중 하나를 수정하면 충분합니다.

1 mongoid.yml에는 생산 부분은 없습니다Heroku에서 설명 된 바와 같이

이 mongoid.yml을 생산 섹션을 추가, 예를 들어,

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

2 Heroku가 취급 개발에 기본적으로

설정 Heroku가 환경을 생산와 같은 응용 프로그램을 레일, 또는 Heroku에서 설명 된 바와 같이, Heroku가 특정 될 새로운 환경, 예를 들어 추가

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

나는이 작업을 발견했습니다 -이 내 컴퓨터

1에 나를 위해 일한 전용 "클라이언트"

production: 
    clients: 
    default: 
     uri: <%= ENV['MONGODB_URI'] %> 
     options: 
     skip_version_check: true 
     safe: true 
2

을 더 "세션"이없는주의 사항 :이 추가하여 config/application.rb

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

2 : 귀하의 몽고 이드를 변경하십시오.에서 YML 예를 들어 (만 mongoid 버전 < 5) :

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 

사람 :

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 
관련 문제