Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to export an ActiveRecord object to seeds.rb?

Is it possible to export data from a database, or run something like Person.find(1).to_seed and copy the output from console into the seeds.rb file?

like image 419
jakedahn Avatar asked Dec 18 '10 08:12

jakedahn


2 Answers

Yes.

Here's a gem – https://github.com/rroblak/seed_dump — that does exactly that.

like image 50
gmile Avatar answered Oct 19 '22 22:10

gmile


Try using seed-fu. You can give SeedFu::Writer a CSV file which will be used to generate a file in the seeds.rb "format". Of course using some database tool you would need to export the database table into a CSV file.

like image 43
Zabba Avatar answered Oct 19 '22 23:10

Zabba