Newbie generate scaffold

Hi Guys

First time on the list and pretty new to the rails way of doing
things, yup I know sorry… another newbie!

anyway, apologies out of the way, this is the problem I am having…

I have purchased the “Agile Development with Rails” book and have
just started running through the ‘Depot’ demo application.

I have got to page 57…

I have my project files all set up in Textmate, I have the databases
setup, with a table called products in depot_development ready to go
with all the right fields in it. I have changed my passwords using
OLDPASSWORD command (i recieved the errors described in the book
until i did this) but when I run “ruby script/generate scaffold
Product Admin” from with in my depot directory as instructed I get
the following error …

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

now I have searched and searched for why this should be… and looked
at the errata … no joy :frowning: … what exactly is the error trying to
tell me?

I kind of get the idea that it is saying that files are missing… but
i thought that is what the “generate scaffold” command was going to do?

please, any help that anyone can offer would be greatly appreciated.

go easy on the new guy please hehehe

3Quid
email - [email protected]

3quid wrote:

when I run “ruby script/generate scaffold Product
Admin” from with in my depot directory as
instructed I get the following error …

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

“ruby script…” gets run from the command line in a Command Window.
The
error message is one you’d see in a browser when you’re running an app
(very
common error, actually). If you’d fill in the gaps, it’ll probably be a
very easy fix.

Best regards,
Bill

Hi Bill / Everyone

Thanks for replying, i am getting that error message via the command
line. Don’t know if that helps diagnose what the problem is?

the book doesnt mention creating any files in the app’s directory
before running the command… is it the case that I should? The only
file I have edited in there is database.yml so that it can connect to
MySQL. Thats all the book instructs you to do other than create the
databases/tables which it said could be done in a GUI app. I used
phpMyAdmin … could this be the problem?

sorry if i am being an ass :slight_smile:

3Quid
email - [email protected]

msn - [email protected]
aim - [email protected]

Hi 3quid,
----- Original Message -----
From: 3quid
To: [email protected]
Sent: 2006-04-03 8:25 AM
Subject: Re: [Rails] newbie generate scaffold

Hi Bill / Everyone

Thanks for replying, i am getting that error message via the command
line. Don’t know if that helps diagnose what the problem is?
[BW] It’s a start. Personally, I’ve never seen that at the command
line before. Makes it an interesting (to me) problem.

the book doesnt mention creating any files in the app’s directory
before running the command… is it the case that I should? The only file
I have edited in there is database.yml so that it can connect to MySQL.
Thats all the book instructs you to do

[BW] That’s all it should take. Only additional step I’ve seen
necessary to date is, on a Windows machine, you might have to grant db
rights to the ODBC@localhost user. But that throws a whole different
error.

other than create the databases/tables which it said could be done in
a GUI app. I used phpMyAdmin … could this be the problem?
[BW] Could be. Probably not, but it’s worth ruling out. Have you
tried creating the database from the command line and tables via script?

[BW] Also, what’s your system environment? What version of RoR are
you using?

sorry if i am being an ass :slight_smile:
[BW] Not at all. And, just FFR, groveling’s not required here :wink:

Best regards,
Bill

3Quid
email - [email protected]

msn - [email protected]
aim - [email protected]

On 3 Apr 2006, at 13:47:54, Bill W. wrote:

3quid wrote:
<snip>


  when I run "ruby script/generate scaffold Product
  Admin" from with in my depot directory as
  instructed I get the following error ...


  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


"ruby script\...." gets run from the command line in a Command 

Window. The
error message is one you’d see in a browser when you’re running an
app (very
common error, actually). If you’d fill in the gaps, it’ll probably
be a
very easy fix.

Best regards,
Bill
_______________________________________________
Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

3quid wrote:

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

Hi,

Could you send the whole error ? ie is there a trace ? Adding -t to
the command line will generate more output.

Presumably ‘script/generate model Product’ worked earlier in the
utorial. Does ‘script/generate controller Admin’ work ? (trying to
narrow it down :slight_smile:

Alan

ok noted re:grovelling! hehe

yeh all the references to the error I could find referred to the
browser displaying it.

i have granted rights to the user that I have specified in the
databse.yml file and as you say that would spit out a different error.

when i get home I will try recreating the databases/table but I dont
see why it would be the issue.

My system is MacOSX 10.4.5, MySQL 4.1, RoR 1.1 … (i have done the
rbconfig repair that is needed for OSX10.4 Tiger)

3Quid
email - [email protected]

msn - [email protected]
aim - [email protected]

Hi Bill/Alan/Everyone

if i run the command as mentioned before, with -t … I get this in
return.

Alan - as far as running those other commands you suggested. I tried
them and they seem to run fine… but I hadnt run them when i got this
output below, as the book’s tutorial doesnt mention running anything
before “ruby script/generate scaffold Product Admin” except when we
made the app using “rails depot”

very confused … this is the output i got …

desktop:/users/3quid/rails/depot 3quid$ ruby script/generate scaffold
Product Admin -t
exists app/controllers/
exists app/helpers/
exists app/views/admin
exists test/functional/
dependency model
exists app/models/
exists test/unit/
exists test/fixtures/
identical app/models/product.rb
identical test/unit/product_test.rb
identical test/fixtures/products.yml
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
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.0/lib/active_record/
connection_adapters/mysql_adapter.rb:293:in columns' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.0/lib/active_record/ base.rb:696:incolumns’
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.0/lib/active_record/
base.rb:1963:in attributes_from_column_definition' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.0/lib/active_record/ base.rb:1347:ininitialize_without_callbacks’
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.0/lib/active_record/
callbacks.rb:236:in initialize' /usr/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/rails_generator/ generators/components/scaffold/scaffold_generator.rb:182:innew’
/usr/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/rails_generator/
generators/components/scaffold/scaffold_generator.rb:182:in
model_instance' /usr/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/rails_generator/ generators/components/scaffold/scaffold_generator.rb:164:increate_sandbox’
/usr/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/rails_generator/
generators/components/scaffold/scaffold_generator.rb:85:in manifest' /usr/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/rails_generator/ generators/components/scaffold/scaffold_generator.rb:85:incall’
/usr/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/rails_generator/
commands.rb:106:in render_template_part' /usr/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/rails_generator/ commands.rb:284:incomplex_template’
/usr/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/rails_generator/
manifest.rb:47:in send' /usr/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/rails_generator/ manifest.rb:47:insend_actions’
/usr/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/rails_generator/
manifest.rb:46:in each' /usr/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/rails_generator/ manifest.rb:46:insend_actions’
/usr/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/rails_generator/
manifest.rb:31:in replay' /usr/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/rails_generator/ commands.rb:41:ininvoke!’
/usr/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/rails_generator/
scripts/…/scripts.rb:31:in run' /usr/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/commands/generate.rb:6 /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:inrequire__’
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in
require' /usr/lib/ruby/gems/1.8/gems/activesupport-1.3.0/lib/active_support/ dependencies.rb:136:inrequire’
script/generate:3

3Quid
email - [email protected]

msn - [email protected]
aim - [email protected]

yup i know hehe… i replied to your post! glad (sort of) to see its
not just me!

when i add -t to the end of the scaffold command, as suggested by one
of the guys on here get the below … does anybody know how we can
solve this problem? or any more people experiencing the same problem
with this section of the book?

desktop:/users/3quid/rails/depot 3quid$ ruby script/generate scaffold
Product Admin -t
exists app/controllers/
exists app/helpers/
exists app/views/admin
exists test/functional/
dependency model
exists app/models/
exists test/unit/
exists test/fixtures/
identical app/models/product.rb
identical test/unit/product_test.rb
identical test/fixtures/products.yml
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
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.0/lib/active_record/
connection_adapters/mysql_adapter.rb:293:in columns' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.0/lib/active_record/ base.rb:696:incolumns’
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.0/lib/active_record/
base.rb:1963:in attributes_from_column_definition' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.0/lib/active_record/ base.rb:1347:ininitialize_without_callbacks’
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.0/lib/active_record/
callbacks.rb:236:in initialize' /usr/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/rails_generator/ generators/components/scaffold/scaffold_generator.rb:182:innew’
/usr/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/rails_generator/
generators/components/scaffold/scaffold_generator.rb:182:in
model_instance' /usr/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/rails_generator/ generators/components/scaffold/scaffold_generator.rb:164:increate_sandbox’
/usr/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/rails_generator/
generators/components/scaffold/scaffold_generator.rb:85:in manifest' /usr/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/rails_generator/ generators/components/scaffold/scaffold_generator.rb:85:incall’
/usr/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/rails_generator/
commands.rb:106:in render_template_part' /usr/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/rails_generator/ commands.rb:284:incomplex_template’
/usr/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/rails_generator/
manifest.rb:47:in send' /usr/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/rails_generator/ manifest.rb:47:insend_actions’
/usr/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/rails_generator/
manifest.rb:46:in each' /usr/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/rails_generator/ manifest.rb:46:insend_actions’
/usr/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/rails_generator/
manifest.rb:31:in replay' /usr/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/rails_generator/ commands.rb:41:ininvoke!’
/usr/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/rails_generator/
scripts/…/scripts.rb:31:in run' /usr/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/commands/generate.rb:6 /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:inrequire__’
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in
require' /usr/lib/ruby/gems/1.8/gems/activesupport-1.3.0/lib/active_support/ dependencies.rb:136:inrequire’
script/generate:3

Would appreciate any help that anyone can offer. I am pretty sure I
have updated/fixed/patched ruby, ruby gems and the mysql bindings,
unless somebody can telll from that error output that i was not
successful with some of that?

thanks

3Quid
email - [email protected]

msn - [email protected]
aim - [email protected]

i am getting the exact same error:

b00ty:/Library/WebServer/Documents/Rails/depot chris$ ruby
script/generate scaffold Product Admin
exists app/controllers/
exists app/helpers/
exists app/views/admin
exists test/functional/
dependency model
exists app/models/
exists test/unit/
exists test/fixtures/
identical app/models/product.rb
identical test/unit/product_test.rb
identical test/fixtures/products.yml
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
b00ty:/Library/WebServer/Documents/Rails/depot chris$

also, on page 57 of the agile book.

i was getting a different error, before i uppt to 5.0 from 4.0 of MySQL,
as none of the “fixes” were fixing anything. =D

3quid wrote:

yup i know hehe… i replied to your post! glad (sort of) to see its
not just me!

when i add -t to the end of the scaffold command, as suggested by one
of the guys on here get the below … does anybody know how we can
solve this problem? or any more people experiencing the same problem
with this section of the book?

The -t will probably need to either after ‘generate’ or after ‘scaffold’
as it’s a flag. You’d do ‘ls -l dirname’ rather than ‘ls dirname -l’,
I’m guessing

script/generate scaffold -t args…

works for me.

A.

Are you both working on the same platform? More info is better.

Thanks,
Bill
----- Original Message -----
From: 3quid
To: [email protected]
Sent: 2006-04-05 2:15 AM
Subject: Re: [Rails] Re: Re: newbie generate scaffold

yup i know hehe… i replied to your post! glad (sort of) to see its
not just me!

when i add -t to the end of the scaffold command, as suggested by one
of the guys on here get the below … does anybody know how we can solve
this problem? or any more people experiencing the same problem with this
section of the book?

desktop:/users/3quid/rails/depot 3quid$ ruby script/generate scaffold
Product Admin -t
exists app/controllers/
exists app/helpers/
exists app/views/admin
exists test/functional/
dependency model
exists app/models/
exists test/unit/
exists test/fixtures/
identical app/models/product.rb
identical test/unit/product_test.rb
identical test/fixtures/products.yml
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
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.0/lib/active_record/connection_adapters/mysql_adapter.rb:293:in
columns' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.0/lib/active_record/base.rb:696:in columns’
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.0/lib/active_record/base.rb:1963:in
attributes_from_column_definition' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.0/lib/active_record/base.rb:1347:in initialize_without_callbacks’
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.0/lib/active_record/callbacks.rb:236:in
initialize' /usr/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb:182:in new’
/usr/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb:182:in
model_instance' /usr/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb:164:in create_sandbox’
/usr/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb:85:in
manifest' /usr/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb:85:in call’
/usr/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/rails_generator/commands.rb:106:in
render_template_part' /usr/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/rails_generator/commands.rb:284:in complex_template’
/usr/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/rails_generator/manifest.rb:47:in
send' /usr/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/rails_generator/manifest.rb:47:in send_actions’
/usr/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/rails_generator/manifest.rb:46:in
each' /usr/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/rails_generator/manifest.rb:46:in send_actions’
/usr/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/rails_generator/manifest.rb:31:in
replay' /usr/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/rails_generator/commands.rb:41:in invoke!’
/usr/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/rails_generator/scripts/…/scripts.rb:31:in
run' /usr/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/commands/generate.rb:6 /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in require__’
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in
require' /usr/lib/ruby/gems/1.8/gems/activesupport-1.3.0/lib/active_support/dependencies.rb:136:in require’
script/generate:3

Would appreciate any help that anyone can offer. I am pretty sure I
have updated/fixed/patched ruby, ruby gems and the mysql bindings,
unless somebody can telll from that error output that i was not
successful with some of that?

thanks

3Quid
email - [email protected]

msn - [email protected]
aim - [email protected]

On 5 Apr 2006, at 06:11:25, Chris C. wrote:

i am getting the exact same error:


b00ty:/Library/WebServer/Documents/Rails/depot chris$ ruby
script/generate scaffold Product Admin
      exists  app/controllers/
      exists  app/helpers/
      exists  app/views/admin
      exists  test/functional/
  dependency  model
      exists    app/models/
      exists    test/unit/
      exists    test/fixtures/
   identical    app/models/product.rb
   identical    test/unit/product_test.rb
   identical    test/fixtures/products.yml
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
b00ty:/Library/WebServer/Documents/Rails/depot chris$






also, on page 57 of the _agile_ book.


i was getting a different error, before i uppt to 5.0 from 4.0 of 

MySQL,
as none of the “fixes” were fixing anything. =D

--
Posted via http://www.ruby-forum.com/.
_______________________________________________
Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

Oops, hold on, it did work anyway as you got the full trace :slight_smile:

Some thoughts.

The line where the failure occurs is trying to retrieve the column
definition for Product. - “SHOW FIELDS FROM #{table_name}” This happens
when the generator tries to call Product.new

Can you show me the SQL and/or migration you’re using for the products
table ?

Also, fire up mysql from the command line.

mysql -u root
use depot_development;
show tables;
show fields from products;

does the table exist ?

If you start script/console, and type:

Product.new

does it work ?

I note that this section of the book is immedately after altering the
sql file to recreate the products table. Perhaps this didn’t work as
expected ?

A.

Alan F. wrote:

I note that this section of the book is immedately after altering the
sql file to recreate the products table. Perhaps this didn’t work as
expected ?

Perhaps the drop worked, but the create failed for some reason…

ok i will try that when i get home…

i know for a fact that the table is there as i checked using
phpMyAdmin but haven’t looked at the table using the command line.

script/console ? is that from mySQL or is that from my RoR app
directory? (sorry that is probably a stupid question!)

3Quid
email - [email protected]

msn - [email protected]
aim - [email protected]

3quid wrote:

ok i will try that when i get home…

i know for a fact that the table is there as i checked using
phpMyAdmin but haven’t looked at the table using the command line.

script/console ? is that from mySQL or is that from my RoR app
directory? (sorry that is probably a stupid question!)

In your RAILS root, where you run script/generate from, run
scriptconsole instead. This gives you an interactive session where you
can play with your models/database.

You can do, for example, “Product.find(:all)”

‘quit’ to quit :slight_smile:

A.

FYI script/console can be tough to get working on OSX, if you have
trouble with that you may try running your Product unit test which
would effectively tell you the same thing (whether Rails can connect
to MySQL, and is your Product model sane)

Create an empty test database with the correct name and edit your
config/database.yml then try the command:

rake clone_structure_to_test

If that works, you know you can connect. Then try:

ruby test/unit/product_test.rb

If that works then everything is probably inline for your model.

If that doesn’t find the problem, you may want to generate a new rails
app to mess around with see if you can generate models and controllers
in the new app.

Also which version of Ruby are you running (ruby-v), should be at least:
ruby 1.8.4 (2005-12-24) [powerpc-darwin7.9.0]

jeff

mysql -u root
use depot_development;
show tables;
show fields from products;

does the table exist ?

yes that all worked fine, database, tables and fields all present and
correct.

If you start script/console, and type:

Product.new

does it work ?

desktop:/users/3quid/Rails/depot 3quid$ script/console
Loading development environment.

Product.new
NoMethodError: 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
from /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.0/lib/
active_record/connection_adapters/mysql_adapter.rb:293:in columns' from /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.0/lib/ active_record/base.rb:696:incolumns’
from /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.0/lib/
active_record/base.rb:1963:in attributes_from_column_definition' from /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.0/lib/ active_record/base.rb:1347:ininitialize_without_callbacks’
from /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.0/lib/
active_record/callbacks.rb:236:in initialize' from (irb):1:innew’
from (irb):1

thats as far as it gets.

Can you show me the SQL and/or migration you’re using for the products
table ?

this is in db/migrate/001_create_products.rb …

class CreateProducts < ActiveRecord::Migration
def self.up
create_table :products do |t|
# t.column :name, :string
end
end

def self.down
drop_table :products
end
end

this is the MySQL i used to create the tables in the first place

drop table if exists products;
create table products (
id int not null auto_increment,
title varchar(100) not null,
description text not null,
image_url varchar(200) not null,
price decimal(10,2) not null,
primary key (id)
);

thanks for your help dude… i am pretty confused hehe

3Quid
email - [email protected]

msn - [email protected]
aim - [email protected]

On 4/3/06, 3quid [email protected] wrote:

I have got to page 57…
The error occured while evaluating nil.each
Hi. Can you run ‘show tables;’ from the mysql prompt (after selecting
your database) and then ‘desc products;’?

After that (assuming they work) try:

ruby script/console

ActiveRecord::Base.connection.execute(“SHOW FIELDS FROM products”)

You should get a Mysql::Result back. The stack traces you posted
indicate that this is specifically what’s failing, so if you can
narrow it down to this one code snippet it might help get to the
bottom of the problem.


Chad F.
http://chadfowler.com
http://pragmaticprogrammer.com/titles/fr_rr/ (Rails Recipes - In Beta!)
http://pragmaticprogrammer.com/titles/mjwti/ (My Job Went to India,
and All I Got Was This Lousy Book)
http://rubycentral.org
http://rubygarden.org
http://rubygems.rubyforge.org (over three million gems served!)

3quid wrote:

yes that all worked fine, database, tables and fields all present and
correct.

Okay. Weird. I was kind of hoping it wouldn’t :slight_smile:

What does your database.yml look like ?

Product.new

does it work ?

desktop:/users/3quid/Rails/depot 3quid$ script/console
Loading development environment.

Product.new
NoMethodError: 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

thats as far as it gets.

Hmmm. That’s DEFINITELY suggesting that the table exists but has no
columns.

Can you show me the SQL and/or migration you’re using for the products
table ?

Okay the migration was created automatically, and if you’re just
following the tutorial, probably isn’t being used.

this is the MySQL i used to create the tables in the first place

drop table if exists products;
create table products (
id int not null auto_increment,
title varchar(100) not null,
description text not null,
image_url varchar(200) not null,
price decimal(10,2) not null,
primary key (id)
);

thanks for your help dude… i am pretty confused hehe

I can’t see anything wrong there :frowning: grrr.

So lets try this, a new rails app.

$ rails mynewapp
$ cd mynewapp
$ mysqladmin -u root create mynewapp_development;
$ script/generate model Product

<edit db/migration/001_create_product.rb>
<remove the # from the # t.column :name, :string line and quit>

$ rake migrate
$ script/generate scaffold Product Admin

That’ll use migrations rather than the raw sql to create the (much
simplified table). Let me know how you get on :slight_smile:

Alan

A.