Newbie: OSX Ruby/MySQL issue?

I’m three pages into the OnLamp RoR Tutorial [1] and am wrestling
with what appears to be a MySQL connection problem.

I’ve created a simple controller called “recipe” with a corresponding
“recipes” mysql table. The recipe controller is just a simple scaffold.

When I browse to “recipe/new”, though, I get these errors:

NoMethodError in RecipeController#new
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.each

Probing further (and checking the archives of this list, esp. [2]), I
tried running script/console and querying MySQL directly. The results
were:

ActiveRecord::Base.connection.execute(“SHOW FIELDS FROM recipe”)
ActiveRecord::StatementInvalid: Mysql::Error: Lost connection to
MySQL server during query: SHOW FIELDS FROM recipe
from /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/
active_record/connection_adapters/abstract_adapter.rb:120:in log' from /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/ active_record/connection_adapters/mysql_adapter.rb:185:in execute’
from (irb):6
==

I’ve reinstalled all of RoR using a validcode.at bash script [3]–
this supposedly fixed all the standard Tiger-Ruby bugs and enabled
the ruby-mysql library, but I’m still having the same problem.

I’ve been googling for answers to this all night and am running out
of ideas. Can anyone who’s familiar with the particulars of this
setup give some advice?

Running: OSX10.4.4, Ruby 1.8.2, Rails 1.1.2, MySQL 4.1.16

Much thanks in advance for the help,

=Tim Jones=

openboxoffice.com

[1] Radar – O’Reilly
[2] http://news.gmane.org/group/gmane.comp.lang.ruby.rails/thread=59878
[3] http://sg.validcode.at/articles/2006/03/31/the-best-way-to-
install-rails-on-os-x

Hi Tim,

Not 100% on the same setup as you, but I have the Hivelogic install
working here on X.4.6.

The first and most likely cause of your problems is here: [ /usr/lib/
ruby/ ] in the quoted text below

ActiveRecord::Base.connection.execute(“SHOW FIELDS FROM recipe”)
ActiveRecord::StatementInvalid: Mysql::Error: Lost connection to
MySQL server during query: SHOW FIELDS FROM recipe
from /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/
active_record/connection_adapters/abstract_adapter.rb:120:in log' from /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/ active_record/connection_adapters/mysql_adapter.rb:185:in execute’
from (irb):6

it should be /usr/local/lib/ruby/… instead of /usr/lib/ruby/…
Note! /LOCAL/

and here: [ Ruby 1.8.2, ]

Running: OSX10.4.4, Ruby 1.8.2, Rails 1.1.2, MySQL 4.1.16

In simpler terms, you have a problem with your PATH value in the
your .bash_login / .bash_profile file. Sort that one out, close the
Terminal window (or start a new session, or logout from your user a/
c) and then run this simple test in a new Terminal/iTerm window at
the prompt:

$ ruby -v

and you should get something similar to this returned: ruby 1.8.4
(2005-12-24) [powerpc-darwin8.6.0] NB!! the ruby 1.8.4 in there,
anything other than ruby 1.8.4 is NO good

IF things still don’t work after this, well then do what I do, check
for typos carefully :wink: Alternatively, check my signature below for
another Ruby/Rails install alternative :slight_smile:

Kind regards,

Mats


“TextMate, coding with an incredible sense of joy and ease”

“RubyOnRails development done the Mac way”

Success!

Had to do a huge amount of googling, reinstalling, recompiling, and
solving additional errors but was ultimately able to get things
running thanks to this advice. Much thanks, Mats.

=T=