# Model method missing

**URL:** <https://www.ruby-forum.com/t/model-method-missing/89277>\
**Category:** Rails\
**Created:** [March 19, 2007, 9:49am UTC](https://www.ruby-forum.com/t/model-method-missing/89277 "2007-03-19T09:49:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![filipk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/ad7895/32.png) [@filipk](https://www.ruby-forum.com/u/filipk)\
**Post date:** [March 19, 2007, 9:49am UTC](https://www.ruby-forum.com/t/model-method-missing/89277/1 "2007-03-19T09:49:04Z")

</div>

I extended one of my model classes with a method, like this:

class Poll \< ActiveRecord::Base

has\_many :poll\_answers

def find\_active\_for  
# […] method body  
end

end

However, when I tried this in the controller class:

def show  
@classroom = Classroom.find params[:id]  
@lesson\_groups = LessonGroup.find :all, :conditions =\> [  
‘classroom\_id=?’, @classroom.id ], :include =\> :lessons

@poll = Poll.find\_active\_for # my model method  
end

…I got a method\_missing:

NoMethodError (undefined method `find_active_for' for Poll:Class): /vendor/rails/activerecord/lib/active_record/base.rb:1129:in`method\_missing’  
/app/controllers/classroom\_controller.rb:9:in `show’

How is that possible? The class (Poll) gets loaded - I’ve inserted debug  
“logger.info” in poll.rb before and after class definition and they show  
up in the logs.

And by the way, I tried accessing this method in a unit test as well,  
with the same results.

---

<div class="post-metadata">

**Author:** ![filipk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/ad7895/32.png) [@filipk](https://www.ruby-forum.com/u/filipk)\
**Post date:** [March 19, 2007, 9:52am UTC](https://www.ruby-forum.com/t/model-method-missing/89277/2 "2007-03-19T09:52:14Z")

</div>

Filip Koczorowski wrote:

> end
> 
> And by the way, I tried accessing this method in a unit test as well,  
> with the same results.

Put a “self.” at the front of the method name:

def self.find\_active\_for

# […] method body

end

–  
Michael W.

---

<div class="post-metadata">

**Author:** ![filipk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/ad7895/32.png) [@filipk](https://www.ruby-forum.com/u/filipk)\
**Post date:** [March 19, 2007, 10:31am UTC](https://www.ruby-forum.com/t/model-method-missing/89277/3 "2007-03-19T10:31:04Z")

</div>

Michael W. wrote:

> Put a “self.” at the front of the method name:
> 
> def self.find\_active\_for
> 
> # […] method body
> 
> end

Thanks, that’s it!

For some odd reason I forgot that the method I was trying to add was a  
class method…
