# Bug in association\_proxy? getting method\_missing

**URL:** <https://www.ruby-forum.com/t/bug-in-association-proxy-getting-method-missing/145567>\
**Category:** Rails\
**Created:** [August 11, 2008, 5:23pm UTC](https://www.ruby-forum.com/t/bug-in-association-proxy-getting-method-missing/145567 "2008-08-11T17:23:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![clemens](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/df788c/32.png) [@clemens](https://www.ruby-forum.com/u/clemens)\
**Post date:** [August 11, 2008, 5:23pm UTC](https://www.ruby-forum.com/t/bug-in-association-proxy-getting-method-missing/145567/1 "2008-08-11T17:23:42Z")

</div>

Using rails 2.1.0

I have a Price class

class Price \< ActiveRecord::Base  
…  
end

which is referenced by Offering

class Offering \< ActiveRecord::Base  
…  
belongs\_to :special\_price, :class\_name =\> ‘Price’, :foreign\_key =\>  
“special\_price\_id”  
…  
def price\_str  
self.special\_price.price\_range\_str  
end  
…  
end

Unless ‘price\_str’ is called the first time (i.e. on the first request  
after mongrel startup), I get

“D:/InstantRails/ruby186-26/lib/ruby/gems/1.8/gems/activerecord-2.1.0/  
lib/active\_record/attribute\_methods.rb:256:in `method_missing' D:/InstantRails/ruby186-26/lib/ruby/gems/1.8/gems/activerecord-2.1.0/ lib/active_record/associations/association_proxy.rb:177:in`send’  
D:/InstantRails/ruby186-26/lib/ruby/gems/1.8/gems/activerecord-2.1.0/  
lib/active\_record/associations/association\_proxy.rb:177:in  
`method_missing' app/models/care_offering.rb:41:in`care\_price\_str’  
app/views/carehome/new\_offering.html.erb:11:in  
`_run_erb_47app47views47carehome47new_offering46html46erb' D:/InstantRails/ruby186-26/lib/ruby/gems/1.8/gems/activerecord-2.1.0/ lib/active_record/associations/association_collection.rb:274:in`method\_missing\_without\_paginate’  
D:/InstantRails/ruby186-26/lib/ruby/gems/1.8/gems/activerecord-2.1.0/  
lib/active\_record/associations/association\_proxy.rb:175:in  
`method_missing' D:/InstantRails/ruby186-26/lib/ruby/gems/1.8/gems/activerecord-2.1.0/ lib/active_record/associations/association_proxy.rb:175:in`each’  
D:/InstantRails/ruby186-26/lib/ruby/gems/1.8/gems/activerecord-2.1.0/  
lib/active\_record/associations/association\_proxy.rb:175:in `send' D:/InstantRails/ruby186-26/lib/ruby/gems/1.8/gems/activerecord-2.1.0/ lib/active_record/associations/association_proxy.rb:175:in`method\_missing’  
D:/InstantRails/ruby186-26/lib/ruby/gems/1.8/gems/activerecord-2.1.0/  
lib/active\_record/associations/association\_collection.rb:274:in  
`method_missing_without_paginate' vendor/plugins/will_paginate/lib/will_paginate/finder.rb:164:in`method\_missing’  
…”

This does not happen with this model class  
class Offering2 \< ActiveRecord::Base  
…  
belongs\_to :price  
…  
def price\_str  
self.price.price\_range\_str  
end  
end

THIS ONLY HAPPENS IN development, not in production mode. Is this just  
a “config.cache\_classes = false” side effect? But why then does it  
only arise in the “indirect referencing scenario”?

Thanks in advance  
Clemens

---

<div class="post-metadata">

**Author:** ![clemens](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/df788c/32.png) [@clemens](https://www.ruby-forum.com/u/clemens)\
**Post date:** [August 11, 2008, 5:27pm UTC](https://www.ruby-forum.com/t/bug-in-association-proxy-getting-method-missing/145567/2 "2008-08-11T17:27:48Z")

</div>

> app/models/care\_offering.rb:41:in `care\_price\_str’  
> app/views/carehome/new\_offering.html.erb:11:in

What’s this CareOffering/care\_price\_str model/method ?

> THIS ONLY HAPPENS IN development, not in production mode. Is this just  
> a “config.cache\_classes = false” side effect? But why then does it  
> only arise in the “indirect referencing scenario”?

I’ve seen things like this when I’ve confused the dependencies system  
by explicitly requiring application classes.

Fred

---

<div class="post-metadata">

**Author:** ![clemens](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/df788c/32.png) [@clemens](https://www.ruby-forum.com/u/clemens)\
**Post date:** [August 11, 2008, 5:36pm UTC](https://www.ruby-forum.com/t/bug-in-association-proxy-getting-method-missing/145567/3 "2008-08-11T17:36:52Z")

</div>

Frederick C. wrote:

> > app/models/care\_offering.rb:41:in `care\_price\_str’  
> > app/views/carehome/new\_offering.html.erb:11:in
> 
> What’s this CareOffering/care\_price\_str model/method ?

I shouldn’t have mixed p-code with real world stack trace 😉  
CareOffering ~ Offering  
care\_price\_str ~ price\_str

sorry

> I’ve seen things like this when I’ve confused the dependencies system  
> by explicitly requiring application classes.  
> could you be more explicit? Do you mean confsuing “has\_one” and  
> “belongs\_to”. Example?

---

<div class="post-metadata">

**Author:** ![clemens](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/df788c/32.png) [@clemens](https://www.ruby-forum.com/u/clemens)\
**Post date:** [August 11, 2008, 5:45pm UTC](https://www.ruby-forum.com/t/bug-in-association-proxy-getting-method-missing/145567/4 "2008-08-11T17:45:58Z")

</div>

On 11 Aug 2008, at 16:36, Clemens W. wrote:

> sorry

Just make sure you haven’t removed the problem at the point you  
transcribed it

> > I’ve seen things like this when I’ve confused the dependencies system  
> > by explicitly requiring application classes.  
> > could you be more explicit? Do you mean confsuing “has\_one” and  
> > “belongs\_to”. Example?

I mean writing

require ‘offering’

when you don’t need to (since hitting Offering will require the file  
for you).

Fred

---

<div class="post-metadata">

**Author:** ![clemens](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/df788c/32.png) [@clemens](https://www.ruby-forum.com/u/clemens)\
**Post date:** [August 11, 2008, 5:51pm UTC](https://www.ruby-forum.com/t/bug-in-association-proxy-getting-method-missing/145567/5 "2008-08-11T17:51:47Z")

</div>

Frederick C. wrote:

> I mean writing
> 
> require ‘offering’
> 
> when you don’t need to (since hitting Offering will require the file  
> for you).  
> bingo! 🙂
