You're writing a migration script for a Rails application which will create a "Priorities" table with columns for name and position. What if you want to initialize it with well known values? Here's the Ruby way:
create_table :priorities do |t| t.column :name, :string t.column :position, :integer end say_with_time "Initializing priorities..." do ["low", "normal", "high"].each_with_index do |elem, i| Priority.create(:name => elem, :position => 1 + i) end end
No comments:
Post a Comment