YAML Syck versus Psych in Rails 3 Madness

I recently had a need to dump a data structure to yaml so that a user can modify some data,  push the files up to a server and quickly bring them into an application.  One developer ran the data dump on his machine,  and then I ran the code to import it on mine.  We were using the same codebase and same gemset with Ruby 1.9.2.  I expected to get a nice import of the data and to be on my merry way.  Instead I got a parse error.

After digging a bit I ran into these posts that talk the entire story.

http://effectif.com/ruby-on-rails/syck-and-psych-yaml-parsers-on-heroku

http://stackoverflow.com/questions/4980877/rails-error-couldnt-parse-yaml

So what was the problem?  The user than ran the dump did not have the libyaml libraries installed on their system so rails fell back to using syck.  This is not ideal.  Personally I think that rails should just include the psych gem and require and explicit setting to drop back to syck.  That way things work the same across environments.  Maybe there is a reason for having things the other way,  but in the meantime if you want to make sure that your yaml works the same across environments add a

gem “psych”

to your Gemfile.

Addendum:

This was an issue because we were using Ruby 1.9.2 where psych is an optional package.  If you are using Ruby 1.9.3 psych is always included.

About Me: I am a Atlanta based, mobile/Android/IOS/AngularJS/Ruby developer, polyglot programmer, founder of Polyglot Programming Inc., wearable technology enthusiast and am interested in the internet of things. You will often find me purr programming and I regularly speak at conferences around the world. I am available for hire! More Posts

Follow Me:
TwitterLinkedInGoogle Plus

I am a Atlanta based, mobile/Android/IOS/AngularJS/Ruby developer, polyglot programmer, founder of Polyglot Programming Inc., wearable technology enthusiast and am interested in the internet of things. You will often find me purr programming and I regularly speak at conferences around the world. I am available for hire!

Posted in rails, ruby