Rails app won't start

1,237 views
Skip to first unread message

sewid

unread,
Feb 4, 2011, 12:54:38 PM2/4/11
to mon...@googlegroups.com
Hi,

I think it's not a specific mongoid / mongodb problem, but maybe somebody can help me. I've just reinstalled my rails environment (rvm, ruby, gems, ...) and if I want to start my rails app or the rails console, I get this message:

Sebastian-Widmanns-MacBook-Pro:config sebastian$ rails c
/Users/sebastian/.rvm/gems/ruby-1.9.2-p136/gems/mongo-1.2.0/lib/mongo/util/support.rb:50:in `validate_db_name': db_name must be a string or symbol (TypeError)
    from /Users/sebastian/.rvm/gems/ruby-1.9.2-p136/gems/mongo-1.2.0/lib/mongo/db.rb:80:in `initialize'
    from /Users/sebastian/.rvm/gems/ruby-1.9.2-p136/gems/mongo-1.2.0/lib/mongo/connection.rb:272:in `new'
    from /Users/sebastian/.rvm/gems/ruby-1.9.2-p136/gems/mongo-1.2.0/lib/mongo/connection.rb:272:in `db'
    from /Users/sebastian/.rvm/gems/ruby-1.9.2-p136/gems/mongoid-2.0.0.rc.7/lib/mongoid/config/database.rb:19:in `configure'
    from /Users/sebastian/.rvm/gems/ruby-1.9.2-p136/gems/mongoid-2.0.0.rc.7/lib/mongoid/config.rb:322:in `configure_databases'
    from /Users/sebastian/.rvm/gems/ruby-1.9.2-p136/gems/mongoid-2.0.0.rc.7/lib/mongoid/config.rb:110:in `from_hash'
    from (eval):2:in `from_hash'
    from /Users/sebastian/.rvm/gems/ruby-1.9.2-p136/gems/mongoid-2.0.0.rc.7/lib/mongoid/railtie.rb:66:in `block in <class:Railtie>'
    from /Users/sebastian/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.4.rc1/lib/rails/initializable.rb:25:in `instance_exec'
    from /Users/sebastian/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.4.rc1/lib/rails/initializable.rb:25:in `run'
    from /Users/sebastian/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.4.rc1/lib/rails/initializable.rb:50:in `block in run_initializers'
    from /Users/sebastian/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.4.rc1/lib/rails/initializable.rb:49:in `each'
    from /Users/sebastian/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.4.rc1/lib/rails/initializable.rb:49:in `run_initializers'
    from /Users/sebastian/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.4.rc1/lib/rails/application.rb:134:in `initialize!'
    from /Users/sebastian/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.4.rc1/lib/rails/application.rb:77:in `method_missing'
    from /Users/sebastian/Sites/rails/event-click/config/environment.rb:5:in `<top (required)>'
    from /Users/sebastian/.rvm/gems/ruby-1.9.2-p136/gems/activesupport-3.0.4.rc1/lib/active_support/dependencies.rb:239:in `require'
    from /Users/sebastian/.rvm/gems/ruby-1.9.2-p136/gems/activesupport-3.0.4.rc1/lib/active_support/dependencies.rb:239:in `block in require'
    from /Users/sebastian/.rvm/gems/ruby-1.9.2-p136/gems/activesupport-3.0.4.rc1/lib/active_support/dependencies.rb:225:in `block in load_dependency'
    from /Users/sebastian/.rvm/gems/ruby-1.9.2-p136/gems/activesupport-3.0.4.rc1/lib/active_support/dependencies.rb:596:in `new_constants_in'
    from /Users/sebastian/.rvm/gems/ruby-1.9.2-p136/gems/activesupport-3.0.4.rc1/lib/active_support/dependencies.rb:225:in `load_dependency'
    from /Users/sebastian/.rvm/gems/ruby-1.9.2-p136/gems/activesupport-3.0.4.rc1/lib/active_support/dependencies.rb:239:in `require'
    from /Users/sebastian/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.4.rc1/lib/rails/application.rb:103:in `require_environment!'
    from /Users/sebastian/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.4.rc1/lib/rails/commands.rb:22:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

Any idea, why?
I use Ruby 1.9.2 and normally Rails 3.0.3, now I tried it with 3.0.4.rc1 - same problem.

Regards,
sewid

Visnu Pitiyanuvath

unread,
Feb 4, 2011, 12:59:05 PM2/4/11
to mon...@googlegroups.com
what does your config/mongoid.yml look like?

sewid

unread,
Feb 4, 2011, 1:06:00 PM2/4/11
to mon...@googlegroups.com
Hi visnup,

here is my mongoid.yml: https://gist.github.com/811464

There is no trailing space or tab in it. And If I check out my sourcecode from yesterday, the same problem occurs.

When I modify my mongoid.yml to look like:
----------
defaults: &defaults
  host: localhost
  allow_dynamic_fields: false
  autocreate_indexes: false
  raise_not_found_error: true
----------
and remove the rest, rails is starting?!?

Regards,
sewid

Visnu Pitiyanuvath

unread,
Feb 4, 2011, 1:14:42 PM2/4/11
to mon...@googlegroups.com
instead of name: sample_app_development it should be database: sample_app_development

sewid

unread,
Feb 4, 2011, 1:17:18 PM2/4/11
to mon...@googlegroups.com
It was database before, i also tried db_name, name, ... - none of those is working (I just re-tried database: ... without success).

I am really confused.

Regards,
sewid

Visnu Pitiyanuvath

unread,
Feb 4, 2011, 1:22:52 PM2/4/11
to mon...@googlegroups.com
can you add a breakpoint at /Users/sebastian/.rvm/gems/ruby-1.9.2-p136/gems/mongo-1.2.0/lib/mongo/util/support.rb:50:in `validate_db_name': db_name must be a string or symbol (TypeError)

and see what db_name is at that point?

sewid

unread,
Feb 4, 2011, 1:35:58 PM2/4/11
to mon...@googlegroups.com
When trying to debug, I get https://gist.github.com/811516

Today is not my day :-(

Visnu Pitiyanuvath

unread,
Feb 4, 2011, 1:39:41 PM2/4/11
to mon...@googlegroups.com
how about if you just throw a good 'ole `puts db_name` into that code?

sewid

unread,
Feb 4, 2011, 1:44:40 PM2/4/11
to mon...@googlegroups.com
Ok, I added the puts like this: 

The result is:

I have no idea, where this 'admin' is coming from and why there is an empty line. Any ideas?

Regards,
sewid

sewid

unread,
Feb 4, 2011, 1:59:51 PM2/4/11
to mon...@googlegroups.com
When I uncomment the
  <<: *defaults

in mongoid.yml, it is working. I'm going to copy the default values to prod, test and dev, so I can continue to work. I have no idea, why this is, but this is a working workaround.

@visnup: Thanks a lot for your help, if you have another idea, please let me know.

Regards
sewid

sewid

unread,
Feb 5, 2011, 2:54:30 AM2/5/11
to mon...@googlegroups.com
After hours of pain in my head, I found the solution:

http://redmine.ruby-lang.org/issues/show/4300

I reinstalled my ruby environment and that was the reason, why rubygems was updated to 1.5.0. Rubygems 1.5.0 changes the yaml parsing default from syck to psych and psych doesn't like the ":<<" in yaml files.

Add this to the beginning of your config/environment.rb, if you have libyaml installed (default with rvm ruby 1.9.2):
require 'yaml'
YAML::ENGINE.yamler= 'syck'

Now, everything works fine.

Regards,
sewid

iEmpire

unread,
Feb 18, 2011, 3:26:15 PM2/18/11
to Mongoid
You've saved my day! Thanks a lot!

Nik

unread,
Feb 23, 2011, 6:29:06 PM2/23/11
to Mongoid
saved mine, too. Ran into the same problem.

m-b

unread,
Feb 26, 2011, 12:40:59 PM2/26/11
to Mongoid
Saved my day also :)
Reply all
Reply to author
Forward
0 new messages