How to Load Data Into DB

Is there a way of automatically initializing a database with sample data? I ask because fixtures seems to be geared towards the test database (different from the development version) and that too it loads one table at a time (maybe I could have calls to all the fixtures in one test file?). Is there a typical way the rest of you are initializing a database with data for usage?

check out seed_fu, http://intridea.com/2008/4/20/seed-fu-simple-seed-data-for-rails

I've also been on projects where migrations are used to seed the data.

Best. Mike

You can also create a controller with generator methods based upon your needs:

def test_products    quantity = params[:id].to_i    quantity.times do |i|      product = Product.new(                 :created_at => Date.today,                 :name => 'Acme yoyo'                 :price => '5.00')      product.save    end      render :text => "Generated #{quantity} products."    end

You can edit this as needed, then execute this via url passing the # of products you want.

Michael Breen wrote:

Michael Breen wrote:

I've also been on projects where migrations are used to seed the data.

Best. Mike

I have encountered some where the migration has "MODEL_NAME".create :FIELD=>VALUE ... it sounds good .. maybe I could try that ... it seems the easiest to do . However, I like the flexibility of fixtures and the controller approach.

You can also create a controller with generator methods based upon
your needs:

Just make sure you don't deploy this controller to the production site.

Best. Mike