create initial record in migration

ruby, ruby-on-rails, ruby-on-rails-3

Solution

See http://edgeguides.rubyonrails.org/migrations.html#migrations-and-seed-data

A better way is to use Rails 'seed' feature: In the `db/seeds.rb` file:

PageEditor.create({:title => 'Events & Training', :content => ''})
PageEditor.create({:title => 'Roof Mount - Training', :content => ''})

Then run `rake db:seed`

Problem

Im trying to create a record in my migration but I am having trouble I've done it before (with the help of my senior developer) and I tried to replicate what he's done but it does not seem to create the record in the database... Heres the migration file ``` class PageEditor < ActiveRecord::Base; end def create_initial_record PageEditor.create({ :title => 'Events & Training', :content => '' }) PageEditor.create({ :title => 'Roof Mount - Training', :content => '' }) end class CreatePageEditors < ActiveRecord::Migration def up create_table :page_editors do |t| t.string :title t.text :content t.timestamps end create_initial_record end def down drop_table :page_editors end end ``` So i've added the roof mount - training part and then ran a rake db:migrate but it does not create the record and does not show up on my index page.......

Original source

Related problems