undefined method `debug' for nil:NilClass(NoMethodError

E

Esen Sagynov

I created very simple AR code to add new record to MySQL table. But I
get " undefined method `debug' for nil:NilClass(NoMethodError)".

Here is the code:
======================================
require 'rubygems'
require 'active_record'

ActiveRecord::Base.establish_connection(
:adapter => "mysql",
:host => "localhost",
:user => "root",
:password => "samplepass",
:database => "db_demo"
)

class City < ActiveRecord::Base
end

City.create:)id => 4, :name => 'Washington')

last_city = City.find:)last)

if last_city
puts %{#{last_city.name} is the last city}
else
puts "There is no any City."
end
======================================

The code is so simple just like explained in
(http://rubylearning.com/satishtalim/ruby_activerecord_and_mysql.html)
and in the Ruby AR documentation. But that undefined method error pops
up anyway. I actually, so many developers encounter the same problem.
Still cannot find the solution.

Any suggestion is appreciated.
 
B

Brian Candler

Esen said:
I created very simple AR code to add new record to MySQL table. But I
get " undefined method `debug' for nil:NilClass(NoMethodError)".

I think you need to show the full backtrace. This will show not only
which line in your sample program triggered the error, but also in which
library it occurred.

Also describe your platform: which operating system and version? Which
version of ruby, and where did you install it from? Which version of
active_record? Which version of mysql client library?
 
M

Manivannan Jeganathan

Esen Sagynov wrote in post #930294:
I created very simple AR code to add new record to MySQL table. But I
get " undefined method `debug' for nil:NilClass(NoMethodError)".

Here is the code:
======================================
require 'rubygems'
require 'active_record'

ActiveRecord::Base.establish_connection(
:adapter => "mysql",
:host => "localhost",
:user => "root",
:password => "samplepass",
:database => "db_demo"
)

class City < ActiveRecord::Base
end

City.create:)id => 4, :name => 'Washington')


Hi,
Have you solved this problem. Me also having same error.
I don't get any error unless I manually input primary id

Working code
City.create:)name => 'Washington')

Error code
City.create(id=> 1 ,:name => 'Washington')

RubyVersion: 1.8.1
Rails Version: 2.2.2
Gem Version: 1.3.2

Thanks in Advance
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top