Rails 3 - '无法解析Yaml'

时间:2011-04-30 16:25:41

标签: ruby-on-rails ruby ruby-on-rails-3 yaml psych

我不知道我做错了什么。我尝试运行'rails c',但它只是给了我一个错误。它在10分钟前工作。 :\

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>'

5 个答案:

答案 0 :(得分:8)

尝试在config / boot.rb

的开头添加它
require 'yaml'
YAML::ENGINE.yamler= 'syck'

答案 1 :(得分:7)

仅供记录,YAML不接受标签作为缩进,它们必须是空格。将标签更改为空格为我解决了^^

答案 2 :(得分:6)

堆栈转储提到了database_configuration,所以我从你的database.yml文件开始。

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

答案 3 :(得分:2)

“无法解析Yaml” 转到你的项目,看到附近的项目名称有一个! sign.open它,看看发生了哪个文件冲突。右键单击该文件,选择Replace with then from Repository。对于所有文件,你改变了代码。然后运行服务器它将工作。

答案 4 :(得分:0)

我在我的一个YAML文件中使用了一个未加引号的*来发出此问题。

fr:
  simple_form:
    yes: Oui
    no:  Non

    required:
      text: required
      mark: "*"

希望它会有所帮助。 :)