Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongoid::Errors::NoSessionConfig in rails consolse

I clone rails app (our company project) and then install everything that related to mongo db and mongoid gem. Then I run the rake db:setup and then rails s. Its working fine, I can access all the sites and do everything. But I got problem in the rails console.

Whenever I do this:

rails c

then

User.first

I will get this error

Loading development environment (Rails 4.1.1) irb(main):001:0> User.first 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 /Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/mongoid-4.0.0.beta2/lib/mongoid/sessions/factory.rb:27:in create' from /Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/mongoid-4.0.0.beta2/lib/mongoid/sessions.rb:65:in with_name' from /Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/mongoid-4.0.0.beta2/lib/mongoid/sessions.rb:105:in mongo_session' from /Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/mongoid-4.0.0.beta2/lib/mongoid/sessions.rb:121:in collection' from /Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/mongoid-4.0.0.beta2/lib/mongoid/sessions/options.rb:161:in method_missing' from /Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/mongoid-4.0.0.beta2/lib/mongoid/contextual/mongo.rb:263:in initialize' from /Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/mongoid-4.0.0.beta2/lib/mongoid/contextual.rb:53:in new' from /Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/mongoid-4.0.0.beta2/lib/mongoid/contextual.rb:53:in create_context' from /Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/mongoid-4.0.0.beta2/lib/mongoid/contextual.rb:35:in context' from /Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/mongoid-4.0.0.beta2/lib/mongoid/contextual.rb:20:in first' from /Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/mongoid-4.0.0.beta2/lib/mongoid/findable.rb:122:in first' from (irb):1 from /Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/railties-4.1.1/lib/rails/commands/console.rb:90:in start' from /Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/railties-4.1.1/lib/rails/commands/console.rb:9:in start' from /Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:69:in console' from /Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:40:in run_command!' from /Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/railties-4.1.1/lib/rails/commands.rb:17:in ' from /Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in require' from /Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:inblock in require' from /Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:232:in load_dependency' from /Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:inrequire' from /Users/rizalmuthi/Documents/Sites/WORK/tapway/bin/rails:8:in <top (required)>' from /Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:241:inload' from /Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:241:in block in load' from /Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:232:inload_dependency' from /Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:241:in load' from /Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in require' from /Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in require' from -e:1:in'irb(main):002:0>

And FYI, this is the mongoid.yml that I generated by run

rails g mongoid:config

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

I have been looking all over google and some blogs, could not figure it out how to fix this. Besides that, we dont use the Rspec tho.

like image 393
kilua Avatar asked Nov 27 '22 13:11

kilua


1 Answers

change your config/application.rb file:

replace it Bundler.require(*Rails.groups)

to it Bundler.require(*Rails.groups(assets: %w(development test)))

like image 70
Adriano Avatar answered Nov 30 '22 23:11

Adriano