Rails无法解析YAML(Psych :: SyntaxError)

时间:2012-08-23 09:08:08

标签: ruby-on-rails-3.2 yaml omniauth

我在Rails 3.2中创建了一个Rails Applocation,我正在尝试使用gem 'omniauth-twitter'来实现 twitter login 。我安装了相同的宝石。现在我尝试在Rails中的 /config/app.yml 中添加我的Twitter凭据:

config/app.yml

development: &default
 s3_bucket_name: xxxx
 aws_access_key_id: xxxx
 aws_secret_access_key: xxxx
 cloud_made_key: xxxx
 facebook_key: "xxxxx"
 facebook_secret: 'xxxxxxx'
 twitter_consumer_key: "xxxx"
 twitter_consumer_secret: "xxxxx"

当我重新启动服务器时,出现以下错误:

 error
/home/swati/.rvm/rubies/ruby-1.9.2-p318/lib/ruby/1.9.1/psych.rb:148:in `parse': couldn't parse YAML at line 8 column 0 (Psych::SyntaxError)
from /home/swati/.rvm/rubies/ruby-1.9.2-p318/lib/ruby/1.9.1/psych.rb:148:in `parse_stream'
from /home/swati/.rvm/rubies/ruby-1.9.2-p318/lib/ruby/1.9.1/psych.rb:119:in `parse'
from /home/swati/.rvm/rubies/ruby-1.9.2-p318/lib/ruby/1.9.1/psych.rb:106:in `load'
from /home/swati/projects/hackathon-io/config/application.rb:77:in `<class:Application>'
from /home/swati/projects/hackathon-io/config/application.rb:13:in `<module:HackathonIo>'
from /home/swati/projects/hackathon-io/config/application.rb:12:in `<top (required)>'
from /home/swati/.rvm/gems/ruby-1.9.2-p290@hackathon-io/gems/railties-3.2.6/lib/rails/commands.rb:53:in `require'
from /home/swati/.rvm/gems/ruby-1.9.2-p290@hackathon-io/gems/railties-3.2.6/lib/rails/commands.rb:53:in `block in <top (required)>'
from /home/swati/.rvm/gems/ruby-1.9.2-p290@hackathon-io/gems/railties-3.2.6/lib/rails/commands.rb:50:in `tap'
from /home/swati/.rvm/gems/ruby-1.9.2-p290@hackathon-io/gems/railties-3.2.6/lib/rails/commands.rb:50:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

我搜索了一个解决方案,发现了同样的问题并实现了rails error, couldn't parse YAML中指定的答案。

/config/boot.rb

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

我重新启动了我的服务器并再次收到错误:

`/home/swati/.rvm/rubies/ruby-1.9.2-p318/lib/ruby/1.9.1/syck.rb:135:in `load': syntax error on line 8, col 22: `   twitter_consumer_key: "xxxxx"' (ArgumentError)
from /home/swati/.rvm/rubies/ruby-1.9.2-p318/lib/ruby/1.9.1/syck.rb:135:in `load'
from /home/swati/projects/hackathon-io/config/application.rb:77:in `<class:Application>'
from /home/swati/projects/hackathon-io/config/application.rb:13:in `<module:HackathonIo>'
from /home/swati/projects/hackathon-io/config/application.rb:12:in `<top (required)>'
from /home/swati/.rvm/gems/ruby-1.9.2-p290@hackathon-io/gems/railties-      3.2.6/lib/rails/commands.rb:53:in `require'
from /home/swati/.rvm/gems/ruby-1.9.2-p290@hackathon-io/gems/railties-3.2.6/lib/rails/commands.rb:53:in `block in <top (required)>'
from /home/swati/.rvm/gems/ruby-1.9.2-p290@hackathon-io/gems/railties-3.2.6/lib/rails/commands.rb:50:in `tap'
from /home/swati/.rvm/gems/ruby-1.9.2-p290@hackathon-io/gems/railties-3.2.6/lib/rails/commands.rb:50:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

我无法弄清楚语法错误。请帮我解决这个错误。

2 个答案:

答案 0 :(得分:1)

我面临同样的问题并通过将所有标签转换为空格并在脚本允许后删除多余空格来解决它(如果代码中有任何空格,我很少)。基本上删除了我的yml文件中的缩进,它解决了问题和应用程序启动。

答案 1 :(得分:0)

我的一个yaml文件出现了同样的错误,在看到Matt关于标签的建议之后,我检查了我的编辑器(SublimeText)并切换到空格而不是缩进标签,它解决了问题。