Rake aborted! You have a nil object when you didn't expect it!

Hi Guys,

I am following the Agile Web Development with Rails 2nd ed pdf - I have
just started Chapter 5 - the "depot" application.

I keep hitting a problem when I execute this command:
        rake db:migrate

I get:

Adam,

The decimal data type is not supported in the current version of Rails
(1.1.6). It should be in the 1.2 version. You can install the 1.2
release candidate, details here:

http://weblog.rubyonrails.org/2006/11/23/rails-1-2-release-candidate-1

Or, you can do something like this in your migration with the current
version:

t.column :price, 'DECIMAL(5,2)'

This passes the column type right to the database and will work with
MySQL.

Aaron

Hi Guys,

I am following the Agile Web Development with Rails 2nd ed pdf - I have
just started Chapter 5 - the "depot" application.

I keep hitting a problem when I execute this command:
        rake db:migrate

I get:

---------------------------------------------------------------------------
== AddPrice: migrating

-- add_column(:products, :price, :decimal, {:default=>0, :precision=>8,
:scale=>2})
rake aborted!
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occured while evaluating nil.[]

(See full trace by running task with --trace)
---------------------------------------------------------------------------

Does anyone have any ideas?

Look at the second page of the PDF (just after the cover page). It tells you how to install a version of Rails that works with the code in the book. Rails 1.2 was supposed to be out at the time the book was printed, but things got delayed a bit…

Dave

Hey guys!

Thanks for sorting this out - I did read the section about v1.2 - but i
must have forgot to actually install it after I followed the OSX
install guide here:
http://blog.duncandavidson.com/2006/04/sandboxing_rail.html

Thankyou all very much!

This programming stuff is quite addictive!

Cheers

Adam

hey guys i seems to be getting an error with Rake

rake aborted!
No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb,
Rakefile.rb)
/opt/local/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1822:in
`load_rakefile'
(See full trace by running task with --trace)

any ideas?

hey guys i seems to be getting an error with Rake

rake aborted!
No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb,
Rakefile.rb)
/opt/local/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1822:in
`load_rakefile'
(See full trace by running task with --trace)

hi Craig

in a shell i did a "which rails"
it returned:
/opt/local/bin/rails

i changed into that drectory and ran the
rake rails:update

but i still get the:
rake aborted!
No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb,
Rakefile.rb)
/opt/local/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1822:in
`load_rakefile'
(See full trace by running task with --trace)

any ideas??

hi Craig

in a shell i did a "which rails"
it returned:
/opt/local/bin/rails

i changed into that drectory and ran the
rake rails:update

but i still get the:
rake aborted!
No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb,
Rakefile.rb)

The paper book had the same instructions right there on the first page (the first paper inside the covers).

-Rob

Rob Biedenharn http://agileconsultingllc.com
Rob@AgileConsultingLLC.com

The paper book had the same instructions right there on the first page
(the first paper inside the covers).

There are a couple paragraphs there about which versions of rails were
available and supported by the book, but no instructions for making sure
your rails install is running the correct version.

So, given that I'm running rails 1.2 now:

% rails --version
Rails 1.2.0

What's the likely cause of having the same "nil object" error as the
original poster?

Did you actually run: rake --trace db:migrate
so you can see where the problem happens?

That's the first thing to do. Since the OP's error happened over 2 years ago (!), you might as well consider your error "new" and post the details. Anyone who generally follows via the mailing list isn't even going to know what the OP context is (unless they go looking like I had to.)

-Rob

Rob Biedenharn http://agileconsultingllc.com
Rob@AgileConsultingLLC.com

Rob Biedenharn wrote:

Did you actually run: rake --trace db:migrate
so you can see where the problem happens?

I did, but the trace information is meaningless to me. I'll paste it in
below.

That's the first thing to do. Since the OP's error happened over 2
years ago (!), you might as well consider your error "new" and post
the details. Anyone who generally follows via the mailing list isn't
even going to know what the OP context is (unless they go looking like
I had to.)

Good point. I'm accessing this through a web forum (found the original
post through google) and didn't realize there was as associated mailing
list (though now I see that it says so at the bottom of the page).

As noted, I'm working from the paper version of the AWDwR book. I'm
using Locomotive2 (2.0.8) as my Ruby/Rails install on MacOS.

In section 6.2 of the book where the second migration is created, I ran
into the following error:

% rake db:migrate
(in /Users/mattp/devel/ruby/depot)
== AddPrice: migrating

-- add_column(:products, :price, :decimal, {:scale=>2, :default=>0,:precision=>8})
rake aborted!
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occured while evaluating nil.[]

(See full trace by running task with --trace)

After finding this thread with the note about rake 1.1.6 vs 1.2
compatibility of the book's instructions, I upgraded rake:

% which gem
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/bin//gem

% sudo gem install rails --version 1.2
Bulk updating Gem source index for: http://gems.rubyforge.org
Install required dependency activesupport? [Yn]
Install required dependency activerecord? [Yn]
Install required dependency actionpack? [Yn]
Install required dependency actionmailer? [Yn]
Install required dependency actionwebservice? [Yn]
Successfully installed rails-1.2.0
Successfully installed activesupport-1.4.0
Successfully installed activerecord-1.15.0

You might want to see where the various version of your gems are located:
  gem list -d activerecord

I suspect your attempts at installing gems are not affecting the ones inside the Locomotive bundle.

Successfully installed actionpack-1.13.0
Successfully installed actionmailer-1.3.0
Successfully installed actionwebservice-1.2.0
Installing ri documentation for activesupport-1.4.0...

lib/active_support/dependencies.rb:52:16: Unrecognized directive 'nodoc'
Installing ri documentation for activerecord-1.15.0...
Installing ri documentation for actionpack-1.13.0...

lib/action_controller/routing.rb:1050:30: ':' not followed by identified
or operator

lib/action_controller/routing.rb:1054:39: ':' not followed by identified
or operator
Installing ri documentation for actionmailer-1.3.0...
Installing ri documentation for actionwebservice-1.2.0...
Installing RDoc documentation for activesupport-1.4.0...

lib/active_support/dependencies.rb:52:16: Unrecognized directive 'nodoc'
Installing RDoc documentation for activerecord-1.15.0...
Installing RDoc documentation for actionpack-1.13.0...

lib/action_controller/routing.rb:1050:30: ':' not followed by identified
or operator

lib/action_controller/routing.rb:1054:39: ':' not followed by identified
or operator
Installing RDoc documentation for actionmailer-1.3.0...
Installing RDoc documentation for actionwebservice-1.2.0...

% rails --version
Rails 1.2.0

However, after that upgrade I'm still seeing the same error from rake
when I try the db migration.

Doing the migrate with --trace now gives this output (sorry, I don't
have the output prior to my rails update)

% rake db:migrate --trace
(in /Users/mattp/devel/ruby/depot)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
== AddPrice: migrating

-- add_column(:products, :price, :decimal, {:scale=>2, :default=>0,:precision=>8})
rake aborted!
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occured while evaluating nil.[]
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/abstract/schema_statements.rb:259:in
`type_to_sql'

Note that this error is happening from within the Locomotive bundled activerecord-1.14.4

Possibly even more importantly, this is in the abstract adapter rather than, say, the MySQL adapter.

What database is defined in your config/database.yml file? Do you have that adapter installed? Does it support the :decimal type?

/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/abstract/schema_statements.rb:122:in
`add_column'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.rb:273:in
`method_missing'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.rb:257:in
`say_with_time'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/1.8/benchmark.rb:293:in
`measure'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.rb:257:in
`say_with_time'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.rb:271:in
`method_missing'
./db/migrate//002_add_price.rb:3:in `real_up'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.rb:210:in
`migrate'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/1.8/benchmark.rb:293:in
`measure'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.rb:210:in
`migrate'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.rb:333:in
`migrate'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.rb:328:in
`migrate'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.rb:295:in
`up'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.rb:286:in
`migrate'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/tasks/databases.rake:4
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in
`execute'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in
`execute'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:357:in
`invoke'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/1.8/thread.rb:135:in
`synchronize'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:350:in
`invoke'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:in
`run'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:in
`run'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/rake-0.7.1/bin/rake:7
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/bin//rake:18

In case of some typo that I'm not spotting (I've double and triple
checked, but that doesn't necessarily mean I've caught everything) I'm
also going to paste the new migration that I'm trying to run:

% cat db/migrate/002_add_price.rb
class AddPrice < ActiveRecord::Migration
def self.up
   add_column :products, :price, :decimal, :precision => 8, :scale =>
2, :default => 0
end

def self.down
   remove_column :products, :price
end
end

Thanks for any help!
  Matt

It's also possible that there's some subtle mismatch between the versions of things expected by the book and the Locomotive bundle. I don't (and haven't) use(d) Locomotive, so I may be casting more suspicion on it than it deserves. :wink:

Do you get the same/similar error if you change :decimal to :float (or perhaps :real)?

-Rob

Rob Biedenharn http://agileconsultingllc.com
Rob@AgileConsultingLLC.com

Rob Biedenharn wrote:

You might want to see where the various version of your gems are
located:
  gem list -d activerecord

I suspect your attempts at installing gems are not affecting the ones
inside the Locomotive bundle.

Since I'm using the 'gem' from inside my Locomotive bundle, I would
expect it to update gems there.. not somewhere else.. but yes that might
be an incorrect assumption.

% which gem
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/bin//gem

% gem list -d activerecord

*** LOCAL GEMS ***

activerecord (1.15.0, 1.14.4)
    Implements the ActiveRecord pattern for ORM.

This seems to imply that was updated, doesn't it?

Note that this error is happening from within the Locomotive bundled
activerecord-1.14.4

Given that it seems that 1.15 is present, how do I affect which one gets
used?

Possibly even more importantly, this is in the abstract adapter rather
than, say, the MySQL adapter.

What database is defined in your config/database.yml file? Do you
have that adapter installed? Does it support the :decimal type?

I'm using the mysql adapter. It worked well enough to get through the
first migration (creating the relevant table and the first columns). I
have no way of identifying what types the adapter supports, other than
possibly trying a bunch of things.. but that only tells us something if
the adapter is working as expected (which it might not be).

Do you get the same/similar error if you change :decimal to :float (or
perhaps :real)?

Changing :decimal (from the example) to :float allows the migration to
proceed. I'm not sure what information to take from that.. is this
because the wrong version of activerecord is being used, and :float has
been replaced with :decimal in 1.15? Is it because there's something
wrong with the mysql adapter and only one of the two works? It seems
like there could be a half-dozen different reasons for that, and I'm not
sure which way to go in order to make my install conform more closely to
what's expected by the book.

Rob Biedenharn wrote:

You might want to see where the various version of your gems are
located:
gem list -d activerecord

I suspect your attempts at installing gems are not affecting the ones
inside the Locomotive bundle.

Since I'm using the 'gem' from inside my Locomotive bundle, I would
expect it to update gems there.. not somewhere else.. but yes that might
be an incorrect assumption.

% which gem
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/bin//gem

% gem list -d activerecord

*** LOCAL GEMS ***

activerecord (1.15.0, 1.14.4)
   Implements the ActiveRecord pattern for ORM.

This seems to imply that was updated, doesn't it?

More recent version of gem give you a bit more information:

$ gem list -d activerecord

*** LOCAL GEMS ***

activerecord (2.1.2, 2.1.0, 2.0.2, 1.15.6, 1.15.5, 1.15.3)
     Author: David Heinemeier Hansson
     Rubyforge: http://rubyforge.org/projects/activerecord
     Homepage: http://www.rubyonrails.org
     Installed at (2.1.2): /Library/Ruby/Gems/1.8
                  (2.1.0): /Library/Ruby/Gems/1.8
                  (2.0.2): /Library/Ruby/Gems/1.8
                  (1.15.6): /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8
                  (1.15.5): /Library/Ruby/Gems/1.8
                  (1.15.3): /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8

     Implements the ActiveRecord pattern for ORM.

Note that this error is happening from within the Locomotive bundled
activerecord-1.14.4

Given that it seems that 1.15 is present, how do I affect which one gets
used?

Normallly, you can control which version of a gem with:

require 'rubygems'
gem 'activerecord', '=1.15.6'

But Rails expects a consisted set of gems between ActiveRecord, ActiveSupport, and ActionPack (views and controllers). You might be able to specify a rails version (and it will specify all the versions that it wants).

Possibly even more importantly, this is in the abstract adapter rather
than, say, the MySQL adapter.

What database is defined in your config/database.yml file? Do you
have that adapter installed? Does it support the :decimal type?

I'm using the mysql adapter. It worked well enough to get through the
first migration (creating the relevant table and the first columns). I
have no way of identifying what types the adapter supports, other than
possibly trying a bunch of things.. but that only tells us something if
the adapter is working as expected (which it might not be).

Do you get the same/similar error if you change :decimal to :float (or
perhaps :real)?

Changing :decimal (from the example) to :float allows the migration to
proceed. I'm not sure what information to take from that.. is this
because the wrong version of activerecord is being used, and :float has
been replaced with :decimal in 1.15? Is it because there's something
wrong with the mysql adapter and only one of the two works? It seems
like there could be a half-dozen different reasons for that, and I'm not
sure which way to go in order to make my install conform more closely to
what's expected by the book.

I'd say that the version of the MySQL connection adapter you have does not support the :decimal type (regardless of the underlying version of the MySQL database). :float and :decimal are separate types so (at least in current versions) both exist (and work!).

If the particular Locomotive bundle is meant to have the "not quite 1.2" Rails version expected by the ADWR2, then I'd have also expected it to work. (Even if it was a Rails 1.2, it ought to be working.)

-Rob

Rob Biedenharn http://agileconsultingllc.com
Rob@AgileConsultingLLC.com

Perhaps define LIBRARY_PATH in your environment? I can't remember if there is a pure ruby adapter for MySQL (I presume that your problem is during the build of the native component).

-Rob

Rob Biedenharn http://agileconsultingllc.com
Rob@AgileConsultingLLC.com