Class Declarations in Rails Migrations

This is an unforgettable mistake i made today while running some migrations in Rails.

Here is the first migration file. It was generated by using this simple command:

ruby script/generate model Articles

Simple enough right? The output of the generation was:

When i went ahead and tried the rake command to migrate to my database: rake db:migrate I kept getting an error “Uninitialized constant Create Articles” Rake Aborted!!

Having forgot that everything in Rails is Object Orientated (extends from one base class or another) i overlooked two things.

  1. I did not declare the class and what base it extended
  2. I did not add the schema file name into my migration file

Usually Rails generates the schema and adds the base class (Active Record) but this time it didn’t. Anyhow the fix was easy enough…

So this is a classic mistake of us all having our moments..Thanks again to the users over at Stack Overflow for helping out. Their are some excellent trouble shooters out there.

1 Comment Class Declarations in Rails Migrations

Leave a Reply

Your email address will not be published. Required fields are marked *