meg*_*gas 76 yaml redcloth ruby-on-rails-3
更新宝石后我得到了这个:
/home/megas/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/psych.rb:148:in `parse': couldn't parse YAML at line 182 column 9 (Psych::SyntaxError)
from /home/megas/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/psych.rb:148:in `parse_stream'
from /home/megas/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/psych.rb:119:in `parse'
from /home/megas/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/psych.rb:106:in `load'
from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/RedCloth-4.2.3/lib/redcloth/formatters/latex.rb:6:in `<module:LATEX>'
from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/RedCloth-4.2.3/lib/redcloth/formatters/latex.rb:3:in `<top (required)>'
from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/RedCloth-4.2.3/lib/redcloth.rb:21:in `require'
from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/RedCloth-4.2.3/lib/redcloth.rb:21:in `<top (required)>'
from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/RedCloth-4.2.3/lib/case_sensitive_require/RedCloth.rb:6:in `require'
from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/RedCloth-4.2.3/lib/case_sensitive_require/RedCloth.rb:6:in `<top (required)>'
from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/bundler-1.0.10/lib/bundler/runtime.rb:68:in `require'
from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/bundler-1.0.10/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/bundler-1.0.10/lib/bundler/runtime.rb:66:in `each'
from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/bundler-1.0.10/lib/bundler/runtime.rb:66:in `block in require'
from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/bundler-1.0.10/lib/bundler/runtime.rb:55:in `each'
from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/bundler-1.0.10/lib/bundler/runtime.rb:55:in `require'
from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/bundler-1.0.10/lib/bundler.rb:120:in `require'
from /home/megas/Work/railscasts/config/application.rb:10:in `<top (required)>'
from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.3/lib/rails/commands.rb:28:in `require'
from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.3/lib/rails/commands.rb:28:in `block in <top (required)>'
from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.3/lib/rails/commands.rb:27:in `tap'
from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.3/lib/rails/commands.rb:27:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Run Code Online (Sandbox Code Playgroud)
ruby-1.9.2-p136 rails 3.0.3
试图重新安装gem RedCloth,没有帮助,系统只想使用4.2.3版本
知道怎么解决吗?谢谢
vic*_*ega 166
你在某处有无效的YAML代码.我的意思是Psych(新的ruby YAML解析器)无效.
如果您不能(或不想)修复您的YAML代码,请尝试加载旧的YAML解析器(syck),在开头添加 config/boot.rb
require 'yaml'
YAML::ENGINE.yamler = 'syck'
Run Code Online (Sandbox Code Playgroud)
我知道,这只是一个"快速而肮脏"的解决方案
stw*_*ert 49
我的常规Rails 3应用程序也有这个问题,因为我使用本地化的yaml文件为日期/时间.
正如您在此提交https://github.com/rails/rails/commit/dc94d81中所看到的, 通过将数组放在单独的行中可以很容易地"修复".
- order: [ :year, :month, :day ]
18 + order:
19 + - :year
20 + - :month
21 + - :day
Run Code Online (Sandbox Code Playgroud)
小智 20
稍微调整了Paul Raupach的答案,当从目录运行时,会在所有子目录中递归地找到所有*.yml文件并测试该文件.我从我的Rails根目录运行它.
require 'yaml'
d = Dir["./**/*.yml"]
d.each do |file|
begin
puts "checking : #{file}"
f = YAML.load_file(file)
rescue StandardError
puts "failed to read #{file}: #{$!}"
end
end
Run Code Online (Sandbox Code Playgroud)
Hon*_*nza 17
许多地方都描述了根本原因,我将再次总结一下.
有两个默认的yaml解析器Psych是新的,你应该使用的那个.Syck是旧的,它没有维护和死亡,它目前用作没有libyaml存在时的后退(通常是非Linux系统).
重要的是你在某处有一些无效的yaml.它很可能是在你的翻译文件中(我有不带引号的字符串,用%表示).只需在生产盒上尝试使用YAML.load_file加载所有yml文件,您就会看到哪一个是坏的.
小智 13
最好修复YAML文件
以下是如何使用irb,因此您不需要可能无法正常工作的rails控制台:
require 'yaml'
YAML::ENGINE.yamler = 'psych'
YAML.load_file('config/locales/xxx.en.yml')
Run Code Online (Sandbox Code Playgroud)
你会得到一个很好的输出,告诉你问题出在哪里:
Psych::SyntaxError: couldn't parse YAML at line 25 column 17
from /home/xxx/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych.rb:148:in `parse'
from /home/xxx/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych.rb:148:in `parse_stream'
from /home/xxx/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych.rb:119:in `parse'
from /home/xxx/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych.rb:106:in `load'
from /home/xxx/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych.rb:205:in `load_file'
from (irb):10
from /home/xxx/.rvm/rubies/ruby-1.9.2-p290/bin/irb:16:in `<main>'
Run Code Online (Sandbox Code Playgroud)
绝对修复你的yaml代码不只是通过强制YAMl使用'syck'来"掩盖"真正的问题.我有同样的问题,在我的本地化文件中发现格式错误的yml语句.如果您只是强制使用较旧的解析器,那么您将无法从项目中其他位置的新解析器中获得所有工作的好处.
小智 6
原始问题的问题出在RedCloth中.我遇到了同样的问题,只是更新到最新版本的RedCloth gem(目前4.2.7)修复了这个问题.
Honza和FlyboyArt的上述建议是合理的,您应该修复任何自定义的YAML,但是RedCloth很受欢迎,大多数用户发现这个问题也使用RedCloth应该确保他们的GemFile添加了这一行:
gem 'RedCloth', ">= 4.2.7"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
81661 次 |
| 最近记录: |