Model method missing

Filip Koczorowski wrote:

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


However, when I tried this in the controller class:

def show
  @classroom = Classroom.find params[:id]
  @lesson_groups = LessonGroup.find :all, :conditions => [
'classroom_id=?', ], :include => :lessons

  @poll = Poll.find_active_for # my model method

...I got a method_missing:

NoMethodError (undefined method `find_active_for' for Poll:Class):
    /app/controllers/classroom_controller.rb:9:in `show'

How is that possible? The class (Poll) gets loaded - I've inserted debug
"" 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.

Put a "self." at the front of the method name:

def self.find_active_for
   # [...] method body