Rails 3 - 'Couldn't parse Yaml'

半世苍凉 提交于 2019-12-07 02:05:57

问题


I don't know what I did wrong. I try to run 'rails c,' but it just gives me an error. It was working 10 minutes ago. :\

C:/Ruby192/lib/ruby/1.9.1/psych.rb:148:in `parse': couldn't parse YAML at line 2
 column 12 (Psych::SyntaxError)
        from C:/Ruby192/lib/ruby/1.9.1/psych.rb:148:in `parse_stream'
        from C:/Ruby192/lib/ruby/1.9.1/psych.rb:119:in `parse'
        from C:/Ruby192/lib/ruby/1.9.1/psych.rb:106:in `load'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/applic
ation/configuration.rb:88:in `database_configuration'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.7/lib/active_r
ecord/railtie.rb:58:in `block (2 levels) in <class:Railtie>'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_
support/lazy_load_hooks.rb:36:in `instance_eval'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_
support/lazy_load_hooks.rb:36:in `execute_hook'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_
support/lazy_load_hooks.rb:43:in `block in run_load_hooks'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_
support/lazy_load_hooks.rb:42:in `each'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_
support/lazy_load_hooks.rb:42:in `run_load_hooks'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.7/lib/active_r
ecord/base.rb:1904:in `<top (required)>'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.7/lib/active_r
ecord/railtie.rb:32:in `block in <class:Railtie>'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/railti
e.rb:180:in `call'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/railti
e.rb:180:in `each'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/railti
e.rb:180:in `load_console'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/applic
ation.rb:154:in `block in load_console'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/applic
ation/railties.rb:11:in `each'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/applic
ation/railties.rb:11:in `all'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/applic
ation.rb:154:in `load_console'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/comman
ds/console.rb:26:in `start'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/comman
ds/console.rb:8:in `start'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/comman
ds.rb:23:in `<top (required)>'
        from script/rails:6:in `require'
        from script/rails:6:in `<main>'

回答1:


The stack dump mentions database_configuration, so I'd start with your database.yml file.

    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application/configuration.rb:88:in `database_configuration'



回答2:


Try adding this at the beginning of config/boot.rb

require 'yaml'
YAML::ENGINE.yamler= 'syck'



回答3:


Just for the record, YAML doesn't accept tabs as indentation, they must be spaces. Changing tabs to spaces solved it for me ^^




回答4:


"Couldn't parse Yaml" Go to your project and see near the project name there is a ! sign.open it and see in which file conflict occurred.right click that file,select Replace with then Latest from Repository.Do this for all the files u changed code.then run the server it will work.




回答5:


I issued this problem with an unquoted * in one of my YAML file.

fr:
  simple_form:
    yes: Oui
    no:  Non

    required:
      text: required
      mark: "*"

Hope it will help. :)



来源:https://stackoverflow.com/questions/5843104/rails-3-couldnt-parse-yaml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!