Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

uninitialized constant while calling worker method in sidekiq

I am using sidekiq gem in rails 3 and I have define a foo_workers.rb in app/workers folder, when I try to call FooWorker.perform_async(@article) in a rails controller named articles I get this error,

uninitialized constant ArticlesController::FooWorker

Can anyone please help me.

like image 624
Nagendra jain Avatar asked Jan 25 '26 12:01

Nagendra jain


2 Answers

Check your pluralization. The file is called foo_workers.rb, which means you're probably defining FooWorkers, not FooWorker. It should be singular. But this is all guessing because you didn't actually post any code.

like image 132
bricker Avatar answered Jan 28 '26 02:01

bricker


The autoload mechanism won't pluralize your class names. So the class FooWorker is expected to be defined in a foo_worker.rb file in some of the autoload paths.

If the file name is different (like foo_workers.rb), Rails won't try to load the class from it.

like image 27
rewritten Avatar answered Jan 28 '26 04:01

rewritten



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!