Best way to export a database table to a YAML file?

There is a rake task for this. You can specify RAILS_ENV if needed; the default is the development environment:

rake db:fixtures:dump
    # Create YAML test fixtures from data in an existing database.

This plugin will add the functionality you want. It was extracted from ActiveRecord so no longer comes by default.

script/plugin install http://github.com/topfunky/ar_fixtures

Then run:

rake db:fixtures:dump MODEL=ModelName


I have been using YamlDb to save the state of my database.

Install it with the following command:

script/plugin install git://github.com/adamwiggins/yaml_db.git 

Use the rake task to dump the contents of Rails database to db/data.yml

rake db:data:dump

Use the rake task to load the contents of db/data.yml into the database

rake db:data:load

This is the creators homepage:

http://blog.heroku.com/archives/2007/11/23/yamldb_for_databaseindependent_data_dumps/