# Get not working

**URL:** <https://www.ruby-forum.com/t/get-not-working/158051>\
**Category:** Ruby\
**Created:** [January 18, 2009, 6:35pm UTC](https://www.ruby-forum.com/t/get-not-working/158051 "2009-01-18T18:35:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![freebird](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/d78d45/32.png) [@freebird](https://www.ruby-forum.com/u/freebird)\
**Post date:** [January 18, 2009, 6:35pm UTC](https://www.ruby-forum.com/t/get-not-working/158051/1 "2009-01-18T18:35:37Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![freebird](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/d78d45/32.png) [@freebird](https://www.ruby-forum.com/u/freebird)\
**Post date:** [January 18, 2009, 9:34pm UTC](https://www.ruby-forum.com/t/get-not-working/158051/2 "2009-01-18T21:34:19Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![freebird](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/d78d45/32.png) [@freebird](https://www.ruby-forum.com/u/freebird)\
**Post date:** [January 18, 2009, 11:27pm UTC](https://www.ruby-forum.com/t/get-not-working/158051/3 "2009-01-18T23:27:51Z")

</div>

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](http://ar.rubyonrails.com) I don’t see any “get” method (either class or  
instance)

---

<div class="post-metadata">

**Author:** ![freebird](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/d78d45/32.png) [@freebird](https://www.ruby-forum.com/u/freebird)\
**Post date:** [January 19, 2009, 9:28am UTC](https://www.ruby-forum.com/t/get-not-working/158051/4 "2009-01-19T09:28:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![freebird](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/d78d45/32.png) [@freebird](https://www.ruby-forum.com/u/freebird)\
**Post date:** [January 19, 2009, 6:38am UTC](https://www.ruby-forum.com/t/get-not-working/158051/5 "2009-01-19T06:38:01Z")

</div>

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 C. 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](http://ar.rubyonrails.com) I don’t see any “get” method (either class or  
> instance)
