2013-07-10 43 views
6

參考https://github.com/mongoid/mongoid/issues/2894#issuecomment-14903927 我已經做了所有必要的更改...仍然問題是有...mongoid的Rails應用程序...(Mongoid :: Errors :: NoSessionConfig):沒有配置可以找到一個名爲'默認'的會話

spec_helper.rb文件

ENV["RAILS_ENV"] ||= 'test' 
require File.expand_path("../../config/environment", FILE) 
require 'rspec/rails' 
require 'rspec/autorun' 
require 'rails/mongoid' 

的Gemfile

gem 'rails', '4.0.0' 
gem 'rspec-rails', '~>2.14.0' 
gem 'mongoid', git: 'https://github.com/mongoid/mongoid.git' 
gem 'bson_ext' 

mongoid.yml

development: 
    sessions: 
    default: 
     database: mongo_demo_development 
    hosts: 
     - localhost:27017 
    options:   
options: 

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

以下是當我運行我的Rails服務器$軌道S的生成錯誤日誌...

/home/nikunj/.rvm/gems/ruby-1.9.3-p385/bundler/gems/mongoid-d52c33bce36a/lib/mongoid/sessions/factory.rb:27:in create': (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. 
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/bundler/gems/mongoid-d52c33bce36a/lib/mongoid/sessions.rb:137:inwith_name' 
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/bundler/gems/mongoid-d52c33bce36a/lib/mongoid/sessions.rb:390:in __session__' 
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/bundler/gems/mongoid-d52c33bce36a/lib/mongoid/sessions.rb:227:inmongo_session' 
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/bundler/gems/mongoid-d52c33bce36a/lib/mongoid/sessions.rb:171:in collection' 
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/bundler/gems/mongoid-d52c33bce36a/lib/mongoid/contextual/mongo.rb:265:ininitialize' 
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/bundler/gems/mongoid-d52c33bce36a/lib/mongoid/contextual.rb:51:in new' 
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/bundler/gems/mongoid-d52c33bce36a/lib/mongoid/contextual.rb:51:increate_context' 
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/bundler/gems/mongoid-d52c33bce36a/lib/mongoid/contextual.rb:34:in context' 
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/bundler/gems/mongoid-d52c33bce36a/lib/mongoid/contextual.rb:18:inlast' 
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/bundler/gems/mongoid-d52c33bce36a/lib/mongoid/findable.rb:130:in last' 
from /home/nikunj/Practice/mongo_demo/app/rules/myrule_book.rb:5:inclass:Myrule_Book' 
from /home/nikunj/Practice/mongo_demo/app/rules/myrule_book.rb:3:in <top (required)>' 
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:423:inload' 
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:423:in block in load_file' 
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:615:innew_constants_in' 
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:422:in load_file' 
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:323:inrequire_or_load' 
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:462:in load_missing_constant' 
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:183:inconst_missing' 
from /home/nikunj/Practice/mongo_demo/config/environments/development.rb:30:in block in <top (required)>' 
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/railties-4.0.0/lib/rails/railtie/configurable.rb:24:inclass_eval' 
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/railties-4.0.0/lib/rails/railtie/configurable.rb:24:in configure' 
from /home/nikunj/Practice/mongo_demo/config/environments/development.rb:1:in' 
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in require' 
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:inblock in require' 
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in load_dependency' 
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:inrequire' 
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/railties-4.0.0/lib/rails/engine.rb:591:in block (2 levels) in <class:Engine>' 
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/railties-4.0.0/lib/rails/engine.rb:590:ineach' 
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/railties-4.0.0/lib/rails/engine.rb:590:in block in <class:Engine>' 
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/railties-4.0.0/lib/rails/initializable.rb:30:ininstance_exec' 
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/railties-4.0.0/lib/rails/initializable.rb:30:in run' 
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/railties-4.0.0/lib/rails/initializable.rb:55:inblock in run_initializers' 
from /home/nikunj/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/tsort.rb:150:in block in tsort_each' 
from /home/nikunj/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/tsort.rb:183:inblock (2 levels) in each_strongly_connected_component' 
from /home/nikunj/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/tsort.rb:210:in block (2 levels) in each_strongly_connected_component_from' 
from /home/nikunj/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/tsort.rb:219:ineach_strongly_connected_component_from' 
from /home/nikunj/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/tsort.rb:209:in block in each_strongly_connected_component_from' 
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/railties-4.0.0/lib/rails/initializable.rb:44:ineach' 
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/railties-4.0.0/lib/rails/initializable.rb:44:in tsort_each_child' 
from /home/nikunj/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/tsort.rb:203:ineach_strongly_connected_component_from' 
from /home/nikunj/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/tsort.rb:182:in block in each_strongly_connected_component' 
from /home/nikunj/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/tsort.rb:180:ineach' 
from /home/nikunj/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/tsort.rb:180:in each_strongly_connected_component' 
from /home/nikunj/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/tsort.rb:148:intsort_each' 
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/railties-4.0.0/lib/rails/initializable.rb:54:in run_initializers' 
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/railties-4.0.0/lib/rails/application.rb:215:ininitialize!' 
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/railties-4.0.0/lib/rails/railtie/configurable.rb:30:in method_missing' 
from /home/nikunj/Practice/mongo_demo/config/environment.rb:5:in' 
from /home/nikunj/Practice/mongo_demo/config.ru:3:in require' 
from /home/nikunj/Practice/mongo_demo/config.ru:3:inblock in ' 
from /home/nikunj/.rvm/gems/[email protected]/gems/rack-1.5.2/lib/rack/builder.rb:55:in instance_eval' 
from /home/nikunj/.rvm/gems/[email protected]/gems/rack-1.5.2/lib/rack/builder.rb:55:ininitialize' 
from /home/nikunj/Practice/mongo_demo/config.ru:in new' 
from /home/nikunj/Practice/mongo_demo/config.ru:in' 
from /home/nikunj/.rvm/gems/[email protected]/gems/rack-1.5.2/lib/rack/builder.rb:49:in eval' 
from /home/nikunj/.rvm/gems/[email protected]/gems/rack-1.5.2/lib/rack/builder.rb:49:innew_from_string' 
from /home/nikunj/.rvm/gems/[email protected]/gems/rack-1.5.2/lib/rack/builder.rb:40:in parse_file' 
from /home/nikunj/.rvm/gems/[email protected]/gems/rack-1.5.2/lib/rack/server.rb:277:inbuild_app_and_options_from_config' 
from /home/nikunj/.rvm/gems/[email protected]/gems/rack-1.5.2/lib/rack/server.rb:199:in app' 
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/railties-4.0.0/lib/rails/commands/server.rb:48:inapp' 
from /home/nikunj/.rvm/gems/[email protected]/gems/rack-1.5.2/lib/rack/server.rb:314:in wrapped_app' 
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/railties-4.0.0/lib/rails/commands/server.rb:75:instart' 
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/railties-4.0.0/lib/rails/commands.rb:78:in block in <top (required)>' 
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/railties-4.0.0/lib/rails/commands.rb:73:intap' 
from /home/nikunj/.rvm/gems/ruby-1.9.3-p385/gems/railties-4.0.0/lib/rails/commands.rb:73:in <top (required)>' 
from bin/rails:4:inrequire' 
from bin/rails:4:in `' 
+0

嗨,Rails.env ='測試'並再次檢查 – Amar

+1

你解決了這個問題嗎? – cortex

+0

你想從你的Gemfile文件中加載一個gem嗎? – parov

回答

1

我有同樣的問題和錯誤消息 - 在我來說,這是造成的,因爲沒有被加載YML配置文件。我加了下面的行

Mongoid.load!('config/mongoid.yml') 

到config/application.rb中,它解決了這個問題

0

可能的問題是在寶石文件,你我以前不提mongoid寶石的版本。在gem文件中更改gem "mongoid"gem "mongoid" , '~> 4.0.2'並運行bundle install重啓服務器和控制檯。

相關問題