# Weird ArgumentError in non-ActiveRecord models

**URL:** <https://www.ruby-forum.com/t/weird-argumenterror-in-non-activerecord-models/190627>\
**Category:** Rails\
**Created:** [June 24, 2010, 6:21am UTC](https://www.ruby-forum.com/t/weird-argumenterror-in-non-activerecord-models/190627 "2010-06-24T06:21:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![candor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/13edae/32.png) [@candor](https://www.ruby-forum.com/u/candor)\
**Post date:** [June 24, 2010, 6:21am UTC](https://www.ruby-forum.com/t/weird-argumenterror-in-non-activerecord-models/190627/1 "2010-06-24T06:21:36Z")

</div>

Hi,

I have a rails (2.3.5) project that has two models that are not  
ActiveRecord based - one is called Wiki and another is called WebApi.

I have been using this in the past, and it was working. However,  
something I did is now causing ArgumentError to be raised when I call  
a class method on WebApi from a Wiki class method. Here is the  
relevant code:

wiki.rb

class Wiki  
def self.get\_url phrase=’’  
response = WebApi.format\_and\_call(WIKIPEDIA\_URL, phrase) #error  
occurs here  
…  
end  
…  
end

web\_api.rb

class WebApi  
def self.format\_and\_call url\_format\_string, phrase)  
…  
end  
end

Here is the error I get:

ArgumentError (wrong number of arguments (0 for 1)):  
app/models/wiki.rb:7:in `get\_url’

On debugging, i notice that the error is coming from a const\_missing  
triggered by the attempt to access the WebApi object (it has nothing  
to do with the Wikipedia Url constant, which is fine). Here is the  
debug session:

/(rdb:18) step  
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/  
gems/1.8/gems/activesupport-2.3.5/lib/active\_support/dependencies.rb:  
91  
if [Object, Kernel].include?(self) || parent == self  
(rdb:18) step  
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/  
gems/1.8/gems/activesupport-2.3.5/lib/active\_support/core\_ext/module/  
introspection.rb:31  
parent\_name ? parent\_name.constantize : Object  
(rdb:18) step  
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/  
gems/1.8/gems/activesupport-2.3.5/lib/active\_support/core\_ext/module/  
introspection.rb:8  
unless defined? @parent\_name  
(rdb:18) next  
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/  
gems/1.8/gems/activesupport-2.3.5/lib/active\_support/core\_ext/module/  
introspection.rb:9  
@parent\_name = name =~ /::[^:]+\Z/ ? $`.freeze : nil  
(rdb:18) next  
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/  
gems/1.8/gems/actionpack-2.3.5/lib/action\_controller/rescue.rb:162  
rescue\_action(exception)  
(rdb:18) exception  
#\<ArgumentError: wrong number of arguments (0 for 1)\>

I had initially named the WebApi class as Web, and thought the problem  
may be due to a name collision, but I tried different names, and get  
the same problem.

I am quite confused, since this seems fairly simple code, and I don’t  
know where to look.

I am using devise, and have delayed\_job as well in the project, but  
not really using it in this case.

Thanks  
Anand

---

<div class="post-metadata">

**Author:** ![candor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/13edae/32.png) [@candor](https://www.ruby-forum.com/u/candor)\
**Post date:** [June 24, 2010, 9:17pm UTC](https://www.ruby-forum.com/t/weird-argumenterror-in-non-activerecord-models/190627/2 "2010-06-24T21:17:26Z")

</div>

I have tried several things in the last few hours - including  
branching, ripping out all the files, and adding the code back one bit  
at a time. I am really out of choices now - one interesting thing -  
this error seems to occur only on the rails app codepath. When I call  
the same function from a unit test, it works fine.

I did suspect that this was due to some gem being out of sync, as  
several articles suggested, so I have removed everything except uri,  
open-uri and nokogiri. It still does repro.

Can someone please advise- at this point, any suggestion is useful.

Thanks  
Anand

---

<div class="post-metadata">

**Author:** ![candor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/13edae/32.png) [@candor](https://www.ruby-forum.com/u/candor)\
**Post date:** [June 25, 2010, 1:18am UTC](https://www.ruby-forum.com/t/weird-argumenterror-in-non-activerecord-models/190627/3 "2010-06-25T01:18:07Z")

</div>

I got a very ugly workaround to work - I created a fresh project from  
scratch (no git, no delayed job, no devise, nothing:-)) and added the  
files in. Then I merged the non-active record models into one (non AR)  
model. So, all calls are within the same class, and this works.

The interesting thing is that the error occurs only where I have calls  
from one non-AR model to another. When i call a non-AR model from an  
AR model it works.

I dont like this at all, since each of the non-AR models is a separate  
model for a reason (at the least to share common code).

Also, i checked out an old branch that had the same scenario, but  
somewhat different code - i.e, it had non-AR models talking to each  
other, but it had no ajax whatsoever (the problems I mentioned occured  
in a project that has ajax views, rjs, etc.). That branch works fine  
on the local machine, so this doesnt seem like an environment problem  
on the machine…

Any pointers would be very helpful, as I dont want to hang on to this  
workaround for too long.

Thanks  
Anand

---

<div class="post-metadata">

**Author:** ![candor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/13edae/32.png) [@candor](https://www.ruby-forum.com/u/candor)\
**Post date:** [June 25, 2010, 10:09pm UTC](https://www.ruby-forum.com/t/weird-argumenterror-in-non-activerecord-models/190627/4 "2010-06-25T22:09:47Z")

</div>

BTW, there is a typo in the code snippet where I am missing an open  
parenthesis. Adding it also causes the problem.  
Can anybody help, please?

Thanks
