I've got a rake task that populates some initial data during my rails application. For instance, nations, states, mobile service providers, etc.

The way in which I've it setup now, is I've got a couple of create claims in files in /db/fittings along with a rake task that processes them. For instance, one model I've is styles. I've got a theme.rb file in /db/fittings that appears such as this:

Theme.delete_all
Theme.create(:id => 1, :name=>'Lite', :background_color=>'0xC7FFD5', :title_text_color=>'0x222222',
                      :component_theme_color=>'0x001277', :carrier_select_color=>'0x7683FF', :label_text_color=>'0x000000',
                      :join_upper_gradient=>'0x6FAEFF', :join_lower_gradient=>'0x000000', :join_text_color=>'0xFFFFFF',
                      :cancel_link_color=>'0x001277', :border_color=>'0x888888', :carrier_text_color=>'0x000000', :public => true)

Theme.create(:id => 2, :name=>'Metallic', :background_color=>'0x000000', :title_text_color=>'0x7299FF',
                      :component_theme_color=>'0xDBF2FF', :carrier_select_color=>'0x000000', :label_text_color=>'0xDBF2FF',
                      :join_upper_gradient=>'0x2B25FF', :join_lower_gradient=>'0xBEFFAC', :join_text_color=>'0x000000',
                      :cancel_link_color=>'0xFF7C12', :border_color=>'0x000000', :carrier_text_color=>'0x000000', :public => true)

Theme.create(:id => 3, :name=>'Blues', :background_color=>'0x0060EC', :title_text_color=>'0x000374',
                      :component_theme_color=>'0x000374', :carrier_select_color=>'0x4357FF', :label_text_color=>'0x000000',
                      :join_upper_gradient=>'0x4357FF', :join_lower_gradient=>'0xffffff', :join_text_color=>'0x000000',
                      :cancel_link_color=>'0xffffff', :border_color=>'0x666666', :carrier_text_color=>'0x000000', :public => true)
puts "Success: Theme data loaded"

The concept here's that I wish to install some stock styles for customers to begin with. I have trouble with this process.

Setting the ID doesn't work. Which means that basically choose to give a theme, let us refer to it as 'Red', i quickly would simply prefer to add the theme statement for this fixture file and call the rake task to reseed the database. Basically do this, because styles fit in with other objects as well as their id's change this re-initialization, all links are damaged.

My real question is to begin with, is a great way to handle seeding a database? Inside a previous publish, it was suggested in my experience.

If that's the case, how do i hard code the IDs, and what are the disadvantages to that particular?

Otherwise, what's the easiest method to seed the database?

I'll truly appreciate lengthy and considered solutions that contain guidelines.

Thanks!

Upgrading as these solutions are slightly outdated (even though some still apply).

Simple feature put in rails 2.3.4, db/seed products.rb

Supplies a new rake task

rake db:seed

Great for inhabiting common static records like states, nations, etc...

http://railscasts.com/episodes/179-seed-data

*Note which you can use fittings should you have had already produced these to also populate using the db:seed task by putting the next inside your seed products.rb file (in the railscast episode):

require 'active_record/fixtures'
Fixtures.create_fixtures("#{Rails.root}/test/fixtures", "operating_systems")