Adding/Inserting content into a table within a rails migration

class CreatePages < ActiveRecord::Migration
  def self.up
     create_table :pages do |t|
        t.integer :parent_id, :default => 0, :null => false
        t.string :title
        t.text :body
        t.integer :position
        t.boolean :hidden, :default => false
        t.boolean :main_nav
        t.boolean :top_nav
        t.boolean :footer_nav
        t.timestamps
      end

      Page.create :title => 'Home', :body => 'This is the home page. Enjoy motte_cms. Be sure to send improvement requests to scott@scottmotte.com.', :main_nav => '1', :footer_nav => '1'
  end

  def self.down
    drop_table :pages
  end
end

Others ways to do this - including fixtures.

Ryan Bates also has an episode on fixtures in Rails 2.0.

Comments