harsh4u
harsh4u

Reputation: 2600

TID-owrsuwi8g WARN: NameError: uninitialized constant NewsWorker in Sidekiq of Rails

I am developing Rails application where send emails using Sidekiq gem.

Create worker then call it like:

Worker File: news_worker.rb

NewsWorker.perform_at(5.minutes.from_now, @news.title, @news.link, @news.image, user_detail.email, user_detail.category_name, type, email_template)

But anyhow its not working and show error message like:

TID-owrsuwi8g WARN: NameError: uninitialized constant NewsWorker

I tried to call from Model and Controller as well but still display same error. My old worked running fine but why this new create not working.. I found many ways but still not sortout.


Update

# /app/workers/news_worker.rb

class NewsWorker
  include Sidekiq::Worker
  include Rails.application.routes.url_helpers

  def perform  news_title, news_link, news_image, email, category_name, type, email_template = nil
    send_to_email(news_title, news_link, news_image, email, category_name, type, email_template)
  end

  def send_to_email news_title, news_link, news_image, email, category_name, type, email_template
    SchoolMailer.send_news(news_title, news_link, news_image, email, category_name, type, email_template).deliver
  end
end

Let me know if any one have idea.

Thanks

Upvotes: 0

Views: 293

Answers (1)

Ahmed Samir Shahin
Ahmed Samir Shahin

Reputation: 558

I think it has something to do with autoload_paths; the workers directory is not auto-loaded.

In config/application.rb add the following line:

config.autoload_paths += %W(#{config.root}/app/workers)

This should do the trick

Upvotes: -1

Related Questions