Archive for August, 2006

Dumping a Table to Yaml

I decided I wanted all 356 rows of a table dumped to a fixture, but
CSV was a disaster. So:

require 'yaml'
js = Journal.find_all
File.open ('dump.yml', "w") do |f|
  js.each do |j|
    f.print YAML.dump ({"j_#{j.id}" => j.attributes})
  end
end

(I actually did it from script/console.) The only caveat is I got a
line of “” between each entry that I had to delete.

Advertisements

Pages

Categories

Copyright ©2008-2013 James E Orchard-Hays, All Rights Reserved