# Undefined method 'find\_by\_sql'

**URL:** <https://www.ruby-forum.com/t/undefined-method-find-by-sql/188211>\
**Category:** Rails\
**Created:** [May 7, 2010, 7:13pm UTC](https://www.ruby-forum.com/t/undefined-method-find-by-sql/188211 "2010-05-07T19:13:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mlle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/eada6e/32.png) [@Mlle](https://www.ruby-forum.com/u/Mlle)\
**Post date:** [May 7, 2010, 7:13pm UTC](https://www.ruby-forum.com/t/undefined-method-find-by-sql/188211/1 "2010-05-07T19:13:32Z")

</div>

Why would I get an undefined method `find\_by\_sql’ for #Example:  
0x981a4e4\> for error when trying to use the find\_by\_sql method in my  
model?

def init\_dictionaries  
tables = find\_by\_sql( “SHOW TABLES FROM thesaurus” )  
@@tables = tables.collect{ |t| t.Tables\_in\_thesaurus }  
end

---

<div class="post-metadata">

**Author:** ![Mlle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/eada6e/32.png) [@Mlle](https://www.ruby-forum.com/u/Mlle)\
**Post date:** [May 7, 2010, 10:08pm UTC](https://www.ruby-forum.com/t/undefined-method-find-by-sql/188211/2 "2010-05-07T22:08:33Z")

</div>

On 7 May 2010 18:11, Mlle [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Why would I get an undefined method `find\_by\_sql’ for #Example:  
> 0x981a4e4\> for error when trying to use the find\_by\_sql method in my  
> model?
> 
> def init\_dictionaries  
> tables = find\_by\_sql( “SHOW TABLES FROM thesaurus” )

I think that should be self.find\_by\_sql as it is a class method.

> @@tables = tables.collect{ |t| t.Tables\_in\_thesaurus }

Not related to your problem but class variables are usually not a good  
idea.

Colin
