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

Hi Guys,

I am following the Agile Web D. 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?

Thanks!

Adam

On Dec 17, 9:57 am, “Adam T.” [email protected] wrote:

– add_column(:products, :price, :decimal, {:default=>0, :precision=>8,
:scale=>2})

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:

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

On Sun, 2006-12-17 at 08:57 -0800, Adam T. wrote:



Does anyone have any ideas?


you need to be running edge rails - I thought there was some discussion
about this in the PDF.

Craig

On Dec 17, 2006, at 5:26 PM, Craig W. wrote:

I am following the Agile Web D. 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

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 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!

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

On Sun, 2006-12-17 at 17:32 -0800, Adam T. wrote:

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)


change directories to rails_root directory first before running rake

Craig

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??

On Sun, 2006-12-17 at 18:36 -0800, Adam T. wrote:

rake aborted!
No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb,
Rakefile.rb)


you are working on an application - any application that you create with
a command
rails APPLICATION_NAME

IS the rails_root and has a Rakefile in it.

Craig

Dave T. wrote:

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…

I’m working from the paper copy of the book and don’t have the benefit
of these instructions from the PDF. Could someone post them here?

I’m using locomotive2, which installed rails 1.1.6. I tried using gem
to update my rails install to 1.2, but I’m still getting the same error
from rake. I assume there’s some other step I’ve missed…

On Jan 12, 2009, at 1:54 PM, Matthew P. wrote:

I’m using locomotive2, which installed rails 1.1.6. I tried using gem
to update my rails install to 1.2, but I’m still getting the same
error
from rake. I assume there’s some other step I’ve missed…

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

-Rob

Rob B. http://agileconsultingllc.com
[email protected]

doh!

thanks Craig! I get it now

the rake rails:update command seems to have ran without any errors

thankyou for all your help!

Adam

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?

On Jan 12, 2009, at 2:43 PM, Matthew P. wrote:

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 B. http://agileconsultingllc.com
[email protected]

Rob B. 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
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' /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

Rob B. 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.

On Jan 12, 2009, at 3:07 PM, Matthew P. wrote:

years ago (!), you might as well consider your error “new” and post

========================================================
compatibility of the book’s instructions, I upgraded rake:
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.

identified

========================================================
– 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?

i386/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/
i386/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/
migrate' /Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/ synchronize’
i386/lib/ruby/gems/1.8/gems/rake-0.7.1/bin/rake:7
def self.up
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 B. http://agileconsultingllc.com
[email protected]

Rob B. wrote:

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!).

Okay, so I’ve attempted to update/replace the mysql adapter and run into
a different problem that I can’t find a documented solution for.

(this is perhaps getting a bit off topic from the original post, but…)
:slight_smile:

My mysql install isn’t in the standard places gem seems to want to look
– it’s installed by fink which puts everything into /sw. How can I
tell gem how to resolve -lmysqlclient? After reading through the --help
and rubygems web site command reference I don’t see a way to specify -L
directories to the gem installer.

Thanks for all your help so far, Rob. I really appreciate it.
Matt

On Jan 12, 2009, at 5:29 PM, Matthew P. wrote:

expect it to update gems there… not somewhere else… but yes that

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 H.
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).

first migration (creating the relevant table and the first
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 B. http://agileconsultingllc.com
[email protected]

Rob B. wrote:

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).

I’m not sure what you mean by “pure ruby adapter.” There is supposedly
a built-in adapter, but notes in AWDwR suggest that it’s incomplete.

Yes, the problem comes during the build of the native component. The
mkmf.log file that’s being left behind has several errors in it, but the
predominant error is the linker being unable to find the mysqlclient
library. The rest seem related to that (missing function calls, etc.)

No joy on setting LIBRARY_PATH or LD_LIBRARY_PATH, I’m afraid. I find
it a bit odd that there’s no command line option to pass build arguments
down to the compile of the native component. I suppose if I really
wanted to make it happen this way I could build my own gem… but it
might just be easier to rip out Locomotive and do a fully manual install
of ruby/rails. I went with it originally because my package manager
(Fink) is now using Rails 2.0.2 which is even less compatible with the
book’s instructions, but if Loco is going to cause me this much trouble,
it’s not worth it.

Thanks again for all your help Rob! We may not have got Locomotive
working, but I ended up with a far, far better understanding of what’s
happening with all the little components than I expected to have at this
point in learning Ruby. :slight_smile:

Cheers,
Matt