user2012677 user2012677 - 16 days ago 5x
Ruby Question

Best way to seed content text in rails 4

I know how to create a standard seed file in rails and seed my database. However, I have a wysiwyg editor that I used to create many pages of content. The content field is a "text" type and contains a full page of HTML. I will be exporting this data out and want to create a seed file with it.

Any ideas on the best way to create my seed files?

For example, should I create a reference the content from separate files? or should I just keep the text in one seed file? Would it be possible to show an example of a recommendation?


Another option if you have multiple attributes and the data is already in the DB, you can use seed_dump gem:

so given an existing DB, running

rake db:seed:dump

will produce the following in the seed.rb:

  { category_id: 1, description: "Long Sleeve Shirt", name: "Long Sleeve Shirt" },
  { category_id: 3, description: "Plain White Tee Shirt", name: "Plain T-Shirt" }
  { password: "123456", username: "test_1" },
  { password: "234567", username: "test_2" }