反馈 本地运行 ruby-china 报错

michael_roshen · 2014年05月14日 · 最后由 michael_roshen 回复于 2014年05月15日 · 3481 次阅读

ruby 版本:ruby-1.9.3-p545 [ x86_64 ] 启动服务器的时候 rails s 报错,什么原因?

chenc@ubuntu:~/gcj_project/gcj_project/ruby-china$ rails s
=> Booting Thin
=> Rails 4.1.1 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--binding option)
=> Ctrl-C to shutdown server
Exiting
/home/chenc/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:264:in `merge!': can't convert nil into Hash (TypeError)
    from /home/chenc/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:264:in `block in revive_hash'
    from /home/chenc/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:258:in `each'
    from /home/chenc/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:258:in `each_slice'
    from /home/chenc/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:258:in `revive_hash'
    from /home/chenc/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:141:in `visit_Psych_Nodes_Mapping'
    from /home/chenc/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/psych/visitors/visitor.rb:15:in `visit'
    from /home/chenc/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/psych/visitors/visitor.rb:5:in `accept'
    from /home/chenc/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:20:in `accept'
    from /home/chenc/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:273:in `block in revive_hash'
    from /home/chenc/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:258:in `each'
    from /home/chenc/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:258:in `each_slice'
    from /home/chenc/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:258:in `revive_hash'
    from /home/chenc/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:141:in `visit_Psych_Nodes_Mapping'
    from /home/chenc/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/psych/visitors/visitor.rb:15:in `visit'
    from /home/chenc/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/psych/visitors/visitor.rb:5:in `accept'
    from /home/chenc/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:20:in `accept'
    from /home/chenc/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:238:in `visit_Psych_Nodes_Document'
    from /home/chenc/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/psych/visitors/visitor.rb:15:in `visit'
    from /home/chenc/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/psych/visitors/visitor.rb:5:in `accept'
    from /home/chenc/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:20:in `accept'
    from /home/chenc/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/psych/nodes/node.rb:35:in `to_ruby'
    from /home/chenc/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/psych.rb:128:in `load'
    from /home/chenc/.rvm/gems/ruby-1.9.3-p545/bundler/gems/mongoid-da35e0cd0fc1/lib/mongoid/config/environment.rb:40:in `load_yaml'
    from /home/chenc/.rvm/gems/ruby-1.9.3-p545/bundler/gems/mongoid-da35e0cd0fc1/lib/mongoid/config.rb:83:in `load!'
    from /home/chenc/.rvm/gems/ruby-1.9.3-p545/bundler/gems/mongoid-da35e0cd0fc1/lib/mongoid.rb:98:in `load!'
    from /home/chenc/.rvm/gems/ruby-1.9.3-p545/bundler/gems/mongoid-da35e0cd0fc1/lib/mongoid/railtie.rb:75:in `block in <class:Railtie>'
    from /home/chenc/.rvm/gems/ruby-1.9.3-p545/gems/railties-4.1.1/lib/rails/initializable.rb:30:in `instance_exec'
    from /home/chenc/.rvm/gems/ruby-1.9.3-p545/gems/railties-4.1.1/lib/rails/initializable.rb:30:in `run'
    from /home/chenc/.rvm/gems/ruby-1.9.3-p545/gems/railties-4.1.1/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /home/chenc/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/tsort.rb:150:in `block in tsort_each'
    from /home/chenc/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/tsort.rb:183:in `block (2 levels) in each_strongly_connected_component'
    from /home/chenc/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/tsort.rb:219:in `each_strongly_connected_component_from'
    from /home/chenc/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/tsort.rb:182:in `block in each_strongly_connected_component'
    from /home/chenc/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/tsort.rb:180:in `each'
    from /home/chenc/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/tsort.rb:180:in `each_strongly_connected_component'
    from /home/chenc/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/tsort.rb:148:in `tsort_each'
    from /home/chenc/.rvm/gems/ruby-1.9.3-p545/gems/railties-4.1.1/lib/rails/initializable.rb:54:in `run_initializers'
    from /home/chenc/.rvm/gems/ruby-1.9.3-p545/gems/railties-4.1.1/lib/rails/application.rb:288:in `initialize!'
    from /home/chenc/gcj_project/gcj_project/ruby-china/config/environment.rb:6:in `<top (required)>'
    from /home/chenc/.rvm/gems/ruby-1.9.3-p545/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `require'
    from /home/chenc/.rvm/gems/ruby-1.9.3-p545/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `block in require'
    from /home/chenc/.rvm/gems/ruby-1.9.3-p545/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:232:in `load_dependency'
    from /home/chenc/.rvm/gems/ruby-1.9.3-p545/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `require'
    from /home/chenc/gcj_project/gcj_project/ruby-china/config.ru:3:in `block in <main>'
    from /home/chenc/.rvm/gems/ruby-1.9.3-p545/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
    from /home/chenc/.rvm/gems/ruby-1.9.3-p545/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
    from /home/chenc/gcj_project/gcj_project/ruby-china/config.ru:in `new'
    from /home/chenc/gcj_project/gcj_project/ruby-china/config.ru:in `<main>'
    from /home/chenc/.rvm/gems/ruby-1.9.3-p545/gems/rack-1.5.2/lib/rack/builder.rb:49:in `eval'
    from /home/chenc/.rvm/gems/ruby-1.9.3-p545/gems/rack-1.5.2/lib/rack/builder.rb:49:in `new_from_string'
    from /home/chenc/.rvm/gems/ruby-1.9.3-p545/gems/rack-1.5.2/lib/rack/builder.rb:40:in `parse_file'
    from /home/chenc/.rvm/gems/ruby-1.9.3-p545/gems/rack-1.5.2/lib/rack/server.rb:277:in `build_app_and_options_from_config'
    from /home/chenc/.rvm/gems/ruby-1.9.3-p545/gems/rack-1.5.2/lib/rack/server.rb:199:in `app'
    from /home/chenc/.rvm/gems/ruby-1.9.3-p545/gems/railties-4.1.1/lib/rails/commands/server.rb:50:in `app'
    from /home/chenc/.rvm/gems/ruby-1.9.3-p545/gems/rack-1.5.2/lib/rack/server.rb:314:in `wrapped_app'
    from /home/chenc/.rvm/gems/ruby-1.9.3-p545/gems/railties-4.1.1/lib/rails/commands/server.rb:130:in `log_to_stdout'
    from /home/chenc/.rvm/gems/ruby-1.9.3-p545/gems/railties-4.1.1/lib/rails/commands/server.rb:67:in `start'
    from /home/chenc/.rvm/gems/ruby-1.9.3-p545/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:81:in `block in server'
    from /home/chenc/.rvm/gems/ruby-1.9.3-p545/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:76:in `tap'
    from /home/chenc/.rvm/gems/ruby-1.9.3-p545/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:76:in `server'
    from /home/chenc/.rvm/gems/ruby-1.9.3-p545/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
    from /home/chenc/.rvm/gems/ruby-1.9.3-p545/gems/railties-4.1.1/lib/rails/commands.rb:17:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

错误信息里面有 psych, mongoid 出现,貌似 mongoid.yml 文件那里有问题,检查一下

defaults: &defaults

development:
  <<: *defaults
  sessions:
    default:
      hosts:
        - 127.0.0.1:27017
      database: ruby_china_dev

test:
  <<: *defaults
  sessions:
    default:
      hosts:
        - 127.0.0.1:27017
      database: ruby_china_test

# set these environment variables on your prod server
production:
  <<: *defaults
  sessions:
    default:
      hosts:
        - 127.0.0.1:27017
      database: ruby_china

没发现哪里有错误。。

#1 楼 @huacnlee

应该是 mogoid.yml 的配置问题,基本能确定,但是找不到原因

#1 楼 @huacnlee 终于搞定了 修改~/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/psych/visitors/to_ruby.rb 第 264 行

private
  def revive_hash hash, o
      ... 
      if key == '<<' 
        case v
        when Nodes::Alias
          hash.merge! accept(v)

to

if key == '<<'  and  accept(v)
需要 登录 后方可回复, 如果你还没有账号请 注册新账号