# Undefined method on web and not in irb

**URL:** <https://www.ruby-forum.com/t/undefined-method-on-web-and-not-in-irb/184744>\
**Category:** Rails\
**Created:** [March 7, 2010, 8:42pm UTC](https://www.ruby-forum.com/t/undefined-method-on-web-and-not-in-irb/184744 "2010-03-07T20:42:17Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![roa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8e7dd6/32.png) [@roa](https://www.ruby-forum.com/u/roa)\
**Post date:** [March 7, 2010, 8:42pm UTC](https://www.ruby-forum.com/t/undefined-method-on-web-and-not-in-irb/184744/1 "2010-03-07T20:42:17Z")

</div>

Hi all

I seem to have a small problem in Rails. Lets say I have a class Foo  
with an habtm association to Bar. So Foo has\_and\_belongs\_to Bars en vice  
versa.

Now, when I do lets say

Foo.new  
Foo.bars, I get an undefined method bars for #Foo:0x1034f2f00 when I  
run it through the browser.

Now, when I do it through irb, it returns an empty array as expected.  
Does someone here has any clue how this can happen and what I need to  
look for, becouse I’m completely clueless.

Thanks for any tips.

---

<div class="post-metadata">

**Author:** ![roa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8e7dd6/32.png) [@roa](https://www.ruby-forum.com/u/roa)\
**Post date:** [March 7, 2010, 8:53pm UTC](https://www.ruby-forum.com/t/undefined-method-on-web-and-not-in-irb/184744/2 "2010-03-07T20:53:57Z")

</div>

On Mar 7, 7:42 pm, Michael R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> run it through the browser.
> 
> Now, when I do it through irb, it returns an empty array as expected.  
> Does someone here has any clue how this can happen and what I need to  
> look for, becouse I’m completely clueless.

Random guess: does this still occur in production mode ?

Fred

---

<div class="post-metadata">

**Author:** ![roa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8e7dd6/32.png) [@roa](https://www.ruby-forum.com/u/roa)\
**Post date:** [March 7, 2010, 8:56pm UTC](https://www.ruby-forum.com/t/undefined-method-on-web-and-not-in-irb/184744/3 "2010-03-07T20:56:33Z")

</div>

Frederick C. wrote:

> On Mar 7, 7:42ï¿½pm, Michael R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > run it through the browser.
> > 
> > Now, when I do it through irb, it returns an empty array as expected.  
> > Does someone here has any clue how this can happen and what I need to  
> > look for, becouse I’m completely clueless.
> 
> Random guess: does this still occur in production mode ?
> 
> Fred

unfortunately is does

---

<div class="post-metadata">

**Author:** ![roa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8e7dd6/32.png) [@roa](https://www.ruby-forum.com/u/roa)\
**Post date:** [March 7, 2010, 10:51pm UTC](https://www.ruby-forum.com/t/undefined-method-on-web-and-not-in-irb/184744/4 "2010-03-07T22:51:03Z")

</div>

On 7 March 2010 19:42, Michael R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> run it through the browser.  
> Foo.bars is not valid as Foo is a class not an instance, or is that  
> just a typo here? It should be something like  
> foo = Foo.new  
> then use foo.bars

Colin

---

<div class="post-metadata">

**Author:** ![roa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8e7dd6/32.png) [@roa](https://www.ruby-forum.com/u/roa)\
**Post date:** [March 7, 2010, 9:06pm UTC](https://www.ruby-forum.com/t/undefined-method-on-web-and-not-in-irb/184744/5 "2010-03-07T21:06:16Z")

</div>

On Mar 7, 7:56 pm, Michael R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > Fred
> 
> unfortunately is does

Is Foo defined in multiple places (some editors leave behind backup  
copies of files that Rails loads anyway) ? If you stick a breakpoint  
in does the Foo object you have look normal apart from raising an  
error when bars is called ?

Fred

---

<div class="post-metadata">

**Author:** ![roa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8e7dd6/32.png) [@roa](https://www.ruby-forum.com/u/roa)\
**Post date:** [March 7, 2010, 11:18pm UTC](https://www.ruby-forum.com/t/undefined-method-on-web-and-not-in-irb/184744/6 "2010-03-07T23:18:01Z")

</div>

Frederick C. wrote:

> On Mar 7, 7:56ï¿½pm, Michael R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > > Fred
> > 
> > unfortunately is does
> 
> Is Foo defined in multiple places (some editors leave behind backup  
> copies of files that Rails loads anyway) ? If you stick a breakpoint  
> in does the Foo object you have look normal apart from raising an  
> error when bars is called ?
> 
> Fred

What just stuk me is that when I set a breakpoint at the class Foo \<  
ActiveRecord::Base line, it doesn’t stop. It just runs through the  
application till it hits foo.bars :s

---

<div class="post-metadata">

**Author:** ![roa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8e7dd6/32.png) [@roa](https://www.ruby-forum.com/u/roa)\
**Post date:** [March 7, 2010, 11:15pm UTC](https://www.ruby-forum.com/t/undefined-method-on-web-and-not-in-irb/184744/7 "2010-03-07T23:15:48Z")

</div>

Colin L. wrote:

> On 7 March 2010 19:42, Michael R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > run it through the browser.  
> > Foo.bars is not valid as Foo is a class not an instance, or is that  
> > just a typo here? It should be something like  
> > foo = Foo.new  
> > then use foo.bars
> 
> Colin

@Colin: yes, sorry for the mistake. I do run foo = Foo.new and then  
foo.bars.

@Fred: just entered a break point. Seems like a normal object of type  
Foo with all its attributes present, except for the associations and  
self declared methods inside my model
