Rails 3 "couldn't parse YAML" error suddenly showing up

I have been developing on the latest Rails 3, Ruby 1.9.2 for a while. and suddenly in 2 projects I started to get this YAML loading error when I try to start my server or run the tests.

bundler./home/mahmoud/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/psych.rb:148:in `parse': couldn't parse YAML at line 55 column 12 (Psych::SyntaxError)
from /home/mahmoud/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/psych.rb:148:in `parse_stream'
from /home/mahmoud/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/psych.rb:119:in `parse'
from /home/mahmoud/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/psych.rb:106:in `load'

It turned out to be related to my recent upgrade of bundler to 1.0.10

After this update, my database.yml was not considered a valid YAML file. until I realized I have to put the special character values (for example: asd@#$asdf@$@) between double quotes.

This fixed the problem for now

I also came across another approach that basically will use a different YAML engine, This is will be the most effective solution because it won't force you to go through all yaml files, specially if you have translation files.
Just include the following lines early in the code (at the beginning of config/boot.rb for example)

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

and voila


Popular posts from this blog

Ruby script for downloading rails casts

Prime Numbers Generator

Exporting data from remote mysql instance in csv, using mysql client and sed