Rails Resque undefined method error in external module

I am having problems calling methods from an included module inside a work resource. In the example below, I continue to get undefined method errors when I try to call the say method inside the worker (which is in the TestLib module). I have illustrated this code to a simple basis:

controller (/app/controllers/test_controller.rb)

 class TestController < ApplicationController def testque Resque.enqueue( TestWorker, "HI" ) end end 

Library (/lib/test_lib.rb)

 module TestLib def say( word ) puts word end end 

employee (/workers/test_worker.rb)

 require 'test_lib' class TestWorker include TestLib @queue = :test_queue def self.perform( word ) say( word ) #returns: undefined method 'say' for TestWorker:Class TestLib::say( word ) #returns: undefined method 'say' for TestLib::Module end end 

Rakefile (Resque.rake)

 require "resque/tasks" task "resque:setup" => :environment 

I run resque using the following command: rake environment resque:work QUEUE='*'

Gemstones: rails (3.0.4) redis (2.2.2) redis-namespace (1.0.3) resque (1.19.0)

Server: nginx / 1.0.6

Anyone have any ideas on what is going on there?

+8
ruby-on-rails resque worker
source share
1 answer

When you turn on a module, its methods become instances. When you expand, they become class methods. You just need to change the include TestLib to extend TestLib , and it should work.

+27
source share

All Articles