I''m getting
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/base.rb:740:
warning: instance variable @columns not initialized
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/base.rb:1494:in
`method_missing'': undefined method `name='' for
#<Device:0x9e1068> (NoMethodError)
from
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/base.rb:1337:in
`send''
from
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/base.rb:1337:in
`attributes=''
from
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/base.rb:1336:in
`each''
from
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/base.rb:1336:in
`attributes=''
from
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/base.rb:1193:in
`initialize_without_callbacks''
from
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/callbacks.rb:236:in
`initialize''
from ./populate_tables2.rb:495:in `new''
from ./populate_tables2.rb:495:in `initialize''
from ./populate_tables2.rb:489:in `open_uri_original_open''
from /usr/local/lib/ruby/1.8/open-uri.rb:87:in `open''
from ./populate_tables2.rb:489:in `initialize''
from ./populate_tables2.rb:553:in `new''
from ./populate_tables2.rb:553
neelix hgs 154 %> !v
view populate_tables2.rb
neelix hgs 155 %> ggrep -C 5 name create_mysql_tables
identifying a piece of equipment.
CREATE TABLE IF NOT EXISTS devices(
`id` int(14) unsigned NOT NULL auto_increment PRIMARY KEY,
`name` varchar(50) NOT NULL default '''',
`serialno` varchar(20) NOT NULL default '''',
`barcode` varchar(20) NOT NULL default '''',
`categorypath` varchar(50) NOT NULL default '''',
`lock_version` integer default 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
neelix hgs 156 %>
I''m using essentially the same code to write the data as for the
other objects that work:
def update_database
@kit.each do |device|
begin
orig_kit = Device.find(:first, :conditions => ["barcode =
?", device.barcode])
rescue Exception => e
puts "Device::update_database: exception is #{e}"
puts "\n", $!, $!.backtrace.join("\n"),
"\n"
end
if orig_kit.nil?
device.save!
else
begin
orig_kit.update_attributes(:name => device.name,
:serialno => device.serialno,
:barcode => device.barcode)
rescue Exception => e
puts "Device::update_database: exception is #{e}"
puts "\n", $!, $!.backtrace.join("\n"),
"\n"
end
end
end
end
And my model is like this:
class Device < ActiveRecord::Base
has_one :device_state
end
Since essentially the same format is OK for the other things in the database
I''m wondering if name and name= are setup differently by default?
Given that it goes through method_missing, how should I lookup this
kind of thing?
If my "special" assumption is wrong, does this ring bells with
anyone please? What should I be looking at for this?
neelix hgs 82 %> gem query -l -n rails
*** LOCAL GEMS ***
rails (0.14.3, 0.13.1)
Web-application framework with template engine, control-flow layer,
and ORM.
neelix hgs 83 %> gem query -l -n activerecord
*** LOCAL GEMS ***
activerecord (1.13.0, 1.11.1)
Implements the ActiveRecord pattern for ORM.
neelix hgs 84 %> ruby --version
ruby 1.8.2 (2004-12-25) [sparc-solaris2.9]
neelix hgs 85 %>
Thank you.
Hugh