2011-04-30 64 views
7

我不知道我做錯了什麼。我嘗試運行'rails c',但它只是給我一個錯誤。它在10分鐘前工作。 :\Rails 3 - '無法解析Yaml'

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

你能告訴我們完整的回溯? – 2011-04-30 16:32:45

+0

當然,編輯了內容。 – Serodis 2011-04-30 16:39:37

+0

值得注意的一件事:我可以使用rails c作爲另一個項目,所以它必須與我的項目相關。 – Serodis 2011-04-30 16:42:01

回答

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

你可以發佈你的config/database.yml文件,它看起來像是該文件中存在問題。 - Rob Di Marco - 請將此作爲回答發佈,我想接受您的回答。 – Serodis 2011-05-05 12:26:57

8

嘗試配置的開頭添加此/的boot.rb

require 'yaml' 
YAML::ENGINE.yamler= 'syck' 
一切順利

+0

由於我的yaml文件中有ü,所以對我有效。 – fivetwentysix 2011-07-26 12:03:44

7

爲了記錄,YAML不接受制表符作爲縮進,它們必須是空格。更改制表符空格解決它對我來說^^

+0

這在Rails 3.1和Ruby 1.9.2.p280中爲我解決了這個問題。不必使用'syck'yaml解析器。 – Jurgen 2011-10-17 22:44:42

0

我發出這個問題,在我的YAML文件之一沒有引號*。

fr: 
    simple_form: 
    yes: Oui 
    no: Non 

    required: 
     text: required 
     mark: "*" 

希望它會有所幫助。 :)

2

「無法解析Yaml」 轉到您的項目,並看到項目名稱附近有一個!打開它並查看發生了哪個文件衝突。右鍵單擊該文件,選擇替換爲最新來自Repository.Do對於所有文件,這改變了code.then運行它將工作的服務器。