Forum: Ruby on Rails Method name= special in some way?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
457cf540784a12ba2f30e06565a2c189?d=identicon&s=25 hgs (Guest)
on 2005-11-28 15:29
(Received via mailing list)
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
457cf540784a12ba2f30e06565a2c189?d=identicon&s=25 hgs (Guest)
on 2005-11-28 16:21
(Received via mailing list)
On Mon, 28 Nov 2005, Hugh Sasse wrote:

>
> 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)

I've now shown it's not the field name, because changing that field to
be
`description` gives an error
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/base.rb:1494:in
`method_missing': undefined method `description=' for
#<Device:0x97ce60> (NoMethodError)

Does anything look familiar to anyone please?
        Hugh
This topic is locked and can not be replied to.