Monday, December 8, 2008

Dumping ActiveRecord objects to yaml

I needed a quick n easy way to move the contents of specified tables (ActiveRecord models) from my production to my development enviro that didn't require a full database backup/restore.  It seems there are a few different plugins/gems to assist with this (like ar_fixtures from nubyonrails), but they seemed like overkill to me. 

Here's a quick snippet to dump the data out to a file for easy transport:

model = User #replace with your model name
f = File.new("/path/to/data/#{model.to_s}.yaml", "w+"); f.puts model.find(:all).to_yaml; f.close

Innagural Post

Hi! This blog is for me to post personal items and record technical feats and failures. 

If you find anything here interesting or useful, please drop me a note letting me know!

Followers