[Rails] Re: Re: Re: newbie generate scaffold

3quid threequid at gmail.com
Wed Apr 5 19:47:49 GMT 2006


> 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:in `columns'
         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:in `initialize_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:in `new'
         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 - threequid at gmail.com
-----------------------------------
msn - threequid at gmail.com
aim - threequid at mac.com
-----------------------------------


On 5 Apr 2006, at 13:45:25, Alan Francis wrote:

> If you start script/console, and type:
>
> Product.new
>
> does it work ?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060405/e6365689/attachment-0001.html


More information about the Rails mailing list