rails error, couldn't parse YAML

Solution 1:

You have invalid YAML code somewhere. I mean invalid for Psych (the new ruby YAML parser).

If you cannot (or don't want to) fix your YAML code, try to load the old YAML parser (syck), adding this at the beginning of config/boot.rb

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

It's just a 'quick and dirty' fix, I know

Solution 2:

My regular Rails 3 App also had this problem, because I was using a localized yaml File for Date/Times.

As you can see in this commit https://github.com/rails/rails/commit/dc94d81 this can be easy "fixed" by placing the array in seperate lines.

         -    order: [ :year, :month, :day ]
    18  +    order:
    19  +      - :year
    20  +      - :month
    21  +      - :day

Solution 3:

A slight tweak on Paul Raupach's answer which, when run from a directory, finds all *.yml files recursively in all sub-directories and tests the file. I ran it from my Rails root dir.

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

Solution 4:

The root cause was described on many places and I will summarize it again.

There are two default yaml parser Psych is the new one, the one you should be using. Syck is the old one, its not maintained and dying, its currently used as fall back for when there is no libyaml present (non-linux systems usually).

The important thing is you have some invalid yaml somewhere. It is most probably in your translation files (I had unquoted strings strating with %). Just try loading all your yml files with YAML.load_file on the production box and you will see which one is the broken one.