What would be a good way to create some predefined instances in the
database for a certain model? For example: categories, genres or user-
roles? They are pretty fixed, although you might want to add or remove
some at a later stage.
Is it a good idea to put something like this in the migration itself?
create_table :roles do |t|
Role.create :name => ‘admin’
Role.create :name => ‘moderator’
Fixtures should be used for test data only. Migrations seem like a
spot for defalt data, but they can become brittle if you try to place
records into the database at that time, as future changes to code
(validations, before_ callbacks, etc) can make them fail, killing your
remaining migrations. Even if it seems like you can get away with it, I
Here’s the way I do it… by making my own rake task.
In your lib/tasks folder, create a file called import.rake