Mongodb / mongoid rails项目 - "在解析第8行第7列的块映射时没有找到预期的键(Psych :: SyntaxError)"

时间:2016-09-09 02:49:42

标签: ruby-on-rails ruby mongodb mongoid

我有一个使用mongodb / mongoid和一些额外的mongodb / mongoid宝石的rails项目:

ruby "2.3.1"
gem 'rails', '4.1.1'
gem 'mongoid'

当我试图运行它时,我得到一个例外:

$ bundle exec rails s
/home/alex/.gem/ruby/2.3.1/gems/activesupport-4.1.1/lib/active_support/values/time_zone.rb:285: warning: circular argument reference - now
=> 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/alex/.rubies/ruby-2.3.1/lib/ruby/2.3.0/psych.rb:377:in `parse': (<unknown>): did not find expected key while parsing a block mapping at line 8 column 7 (Psych::SyntaxError)
        from /home/alex/.rubies/ruby-2.3.1/lib/ruby/2.3.0/psych.rb:377:in `parse_stream'
        from /home/alex/.gem/ruby/2.3.1/gems/mongoid-4.0.2/lib/mongoid/config/environment.rb:40:in `load_yaml'
        from /home/alex/.gem/ruby/2.3.1/gems/mongoid-4.0.2/lib/mongoid/config.rb:83:in `load!'
        # ............skipped
        from /home/alex/.gem/ruby/2.3.1/gems/railties-4.1.1/lib/rails/initializable.rb:55:in `block in run_initializers'
        from /home/alex/.rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:228:in `block in tsort_each'
        from /home/alex/.rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
        from /home/alex/.rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:431:in `each_strongly_connected_component_from'
        from /home/alex/.rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:349:in `block in each_strongly_connected_component'
        # .......... skipped
        from /home/alex/.gem/ruby/2.3.1/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:232:in `load_dependency'
        from /home/alex/.gem/ruby/2.3.1/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `require'
        from /home/alex/projects/ruby/my_project_123/config.ru:3:in `block in <main>'
        from /home/alex/.gem/ruby/2.3.1/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
        # ............skipped
        from /home/alex/.gem/ruby/2.3.1/gems/railties-4.1.1/lib/rails/commands.rb:17:in `<top (required)>'
        from bin/rails:4:in `require'
        from bin/rails:4:in `<main>'

什么可能导致此异常?

1 个答案:

答案 0 :(得分:2)

Psych是一个YAML解析器和发射器。错误指示yml文件中的某个位置在键值之前有额外的空格(或者没有足够的空格)。检查所有yml文件(例如:mongoid.yml)以获得正确的语法。您可以验证您的yml文件Here。例如,在以下YAML

key_one:
  inner:
  - value1
  - value2

key_two:
    inner:
  - value1
  - value2

第7行第5列在键值

之前有一个额外的空格