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   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.

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

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