Get not working

I have a class Halt. If i type Halt, the output is

Halt

=> Halt(id: integer, troute_id: integer, seq: integer, day: integer,
arrival: integer, departure: integer, duration: integer, tnode_id:
integer, mode: string, junction: boolean, distance: integer, created_at:
datetime, updated_at: datetime)

The database is populated. And code was working. But recently it stop
working.
If i type Halt.get, this is the output:

Halt.get(1)

NoMethodError: undefined method `get' for #<Class:0xb7025de8>
  from
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:1833:in
`method_missing'
  from (irb):3

can you please suggest why this is happeneing?

···

--
Posted via http://www.ruby-forum.com/\.

I have a class Halt. If i type Halt, the output is

Halt

=> Halt(id: integer, troute_id: integer, seq: integer, day: integer,
arrival: integer, departure: integer, duration: integer, tnode_id:
integer, mode: string, junction: boolean, distance: integer, created_at:
datetime, updated_at: datetime)

presumably Halt is both a method Halt() and a class... we can only guess since you don't provide any code.

The database is populated. And code was working. But recently it stop
working.
If i type Halt.get, this is the output:

Halt.get(1)

In this case you're trying to execute the #get class method on the Halt class. That's what the parser sees at least. I'm guessing (again) that you don't have a #get class method and you're instead expecting to call the #get instance method on whatever the #Halt method returns. If you want to ensure that you're calling your method, add parens:

   Halt().get(1)

I don't think it is a good design to have an argless global method with the same name as the class. you get confusion like the above.

···

On Jan 18, 2009, at 09:34 , Free Bird wrote:

Free Bird wrote:

If i type Halt.get, this is the output:

Halt.get(1)

NoMethodError: undefined method `get' for #<Class:0xb7025de8>
  from
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:1833:in
`method_missing'
  from (irb):3

can you please suggest why this is happeneing?

Did you mean Halt.find(1) ?

At ar.rubyonrails.com I don't see any "get" method (either class or
instance)

···

--
Posted via http://www.ruby-forum.com/\.

I have one db entry:(/db/migrate)

class CreateHalts < ActiveRecord::Migration
  def self.up
    create_table :halts do |t|
      t.integer :troute_id, :null => false
      t.integer :seq
      t.integer :day
      t.integer :arrival
      t.integer :departure
      t.integer :duration
      t.integer :tnode_id, :null => false
      t.string :mode
      t.boolean :junction
      t.integer :distance
      t.timestamps
    end
    execute "alter table halts add constraint fk_halt_troutes foreign
key (troute_id) references troutes(id)"
    execute "alter table halts add constraint fk_halt_tnodes foreign key
(tnode_id) references tnodes(id)"
  end

  def self.down
    drop_table :halts
  end
end

and i have one model (app/models)

# == Schema Information
# Schema version: 20081211325430

···

#
# Table name: halts
#
# id :integer(4) not null, primary key
# troute_id :integer(4) not null
# seq :integer(4)
# day :integer(4)
# arrival :integer(4)
# departure :integer(4)
# duration :integer(4)
# tnode_id :integer(4) not null
# mode :string(255)
# junction :boolean(1)
# distance :integer(4)
# created_at :datetime
# updated_at :datetime
#

class Halt < ActiveRecord::Base
  belongs_to :troute
  belongs_to :tnode
  validates_presence_of :troute_id, :tnode_id
end

earlier, after populating database,
Halt.get(1) was working.

Brian Candler wrote:

Free Bird wrote:

If i type Halt.get, this is the output:

Halt.get(1)

NoMethodError: undefined method `get' for #<Class:0xb7025de8>
  from
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:1833:in
`method_missing'
  from (irb):3

can you please suggest why this is happeneing?

Did you mean Halt.find(1) ?

At ar.rubyonrails.com I don't see any "get" method (either class or
instance)

--
Posted via http://www.ruby-forum.com/\.

Free Bird wrote:

earlier, after populating database,
Halt.get(1) was working.

How sure are you? I also use activerecord-2.2.2, and 'get' just gives
NoMethodError. I have also checked through the gem source and find no
'def get' or 'def self.get'.

If it did work at one time, then I think you must either have installed
some plugin, or defined your own 'get' class method.

···

--
Posted via http://www.ruby-forum.com/\.