简体   繁体   中英

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM