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.
--
Posted via http://www.ruby-forum.com/.
Esen Sagynov wrote:
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?
···
--
Posted via http://www.ruby-forum.com/\.
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
···
--
Posted via http://www.ruby-forum.com/\.