Very Stuck

Ok I have been trying to get started with Ruby on Rails and I want to
tie it together with a mysql database. I have been using the
examples in teh Agile Web Developkent with Rails, which has you setup
the database.yml file and run rake db:migrate to make sure you can
connect.

Well this all works great.

Next you create a model using script/generate model Account

Once this is created if you run rake db:migrate it will fail. Giving
you an unitialized constant CreateAccount error.

After doing some research online it appears the the file that is
generated is named wrong and that is much exactly match the name of
the class definition inside the migration file.
The generated file is 001_create_accounts.rb

/************ Migration File 001_create_accounts.rb
class CreateAccounts < ActiveRecord::Migration
def self.up
create_table :accounts do |t|
end
end

def self.down
drop_table :accounts
end
end

/*************************

I renamed the file to 001_CreateAccounts.rb, however now I get this :

vincent-cordaros-computer:~/Development/WorkSpace/rails/mymeetingstone
Storm$ rake db:migrate – trace
(in /Users/Storm/Development/WorkSpace/rails/mymeetingstone)


  * config.breakpoint_server has been deprecated and has no

effect. *


rake aborted!
You have a nil object when you didn’t expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.first

Anyone have any ideas or can point me to a good working code example.
I just really want to leverage the object relational mapping
of Rails.

Vince wrote:

Once this is created if you run rake db:migrate it will fail. Giving
def self.up

The generated filename is correct, and it looks right to me. My first
suspicion was that you were migrating an empty table, but I just tried
and that works for me. The error you’re getting doesn’t really suggest
a DB problem to me, it suggests some other problem with your rails
setup. How did you install Rails? following the instructions at
rubyonrails.org? or are you using Instant Rails? Or if you’re on linux,
did you use a package manager?


http://www.5valleys.com/

Once you migrate the db(rake db:migrate), you can’t rename the
migration or add anything to it. You have to generate a new migration,
script/generate model Accounts, then db:migrate and it should work.

jg wrote:

Once you migrate the db(rake db:migrate), you can’t rename the
migration or add anything to it. You have to generate a new migration,
script/generate model Accounts, then db:migrate and it should work.

As I understand, he said it “failed” the first time, with an
Uninitialized Constant error. The problem isn’t trying to rename it
after running it. The problem is trying to get it to run successfully
the first time.


http://www.5valleys.com/