Topic: NoMethodError on Model's find method

Hi All,

I don't know how this could happen. I got NoMethodError on running a simple Model's find method. At first i have the same error for running find_all_by_country method where country is one of the model's attributes. So, running a find method also doesn't help. I have no problem running the methods on rails console.

Here's the pastie http://pastie.org/694864 that describe my situation. As you see the console section, flc is a Clan record. I can ran 'find_all_by_country' method. However, when i ran the 'users_within_country' method, i got NoMethodError on line 2.

I was suggested to use searchlogic gem on other group and i got similar error

NoMethodError: undefined method `country_equals` for Clan

This is the first time my app running on a frozen rails 2.3.4 on OSX 10.6.2, ruby 1.8.7 p174 (compiled from the source). I tried this app on other ruby versions like: 1.8.7p72 (comes from Snow Leopard DVD), 1.8.6p114 on OpenSuSE and i still have the same error. I'm using frozen Rails 2.3.4. I don't know what to do now? What should i check? Any suggestion?

Thanks,
Adinda P

Re: NoMethodError on Model's find method

I think the problem is that you are calling a class method on an object Clan. On any object of Clan type you can call only instance methods, all the finders can be called on self; i.e. Clan.find_method. Tink of it as it is a static method in Java. In your case 'self' doesn't  represents Clan class anumore but an object of type Clan. That's why Rails tries to find an instance method 'find_something' and doen't find it.

Last edited by Javix (2009-11-13 04:45:38)

Re: NoMethodError on Model's find method

You're right. Thank you!