Andrew Grimm
Andrew Grimm

Reputation: 81490

Official documentation for seeding in Ruby on Rails

Is there any official documentation on seeding in Ruby on Rails?

I've come across third-party documentation in the form of a Railscast episode on it, but I'd also like to know what documentation if any the Rails team has produced.

In the Rails guides post on ActiveRecord Migrations, there's a section saying that you should use seeding, but not an awful lot of information on how to do so, and no links to relevant information. Doing a google search of the API using seed site:api.rubyonrails.org doesn't help either.

Upvotes: 1

Views: 459

Answers (1)

max
max

Reputation: 101831

The main reason you're having a hard time finding API documentation is because there really isn't that much to it. There is just a rake task rake db:seed which will require db/seeds.rb.

rake db:seed is in turn invoked by other tasks such as rake db:reset

The seed files in many projects are just some declarative or imperative code which creates a bunch of model instances. The gem Faker is pretty handy for these kinds of tasks (creating pseudo-random filler data for the dev. env.).

I have used it sometimes to mirror the production db with heroku pg:backups.

Upvotes: 1

Related Questions