是否可以通过Sidekiq worker的Mongoid编写MongoDB文件?
# lib/worker.rb
require 'sidekiq'
require 'model' # lib/model.rb
class AwesomeWorker
include Sidekiq::Worker
def perform
RandomNumberModel.create! { random_number: Random.new.rand(1..100) }
end
end
当我运行Sidekiq时,它返回uninitialized constant AwesomeWorker::RandomNumberModel
我做错了什么?
答案 0 :(得分:0)
尝试:: RandomNumberModel.create! {random_number:Random.new.rand(1..100)}
如果失败,你在错误的路径中找到了所需的文件
答案 1 :(得分:0)
可以帮助任何人:)
您必须在app > workers
文件夹下创建您的工作人员。然后,每个模型都可以在那里轻松访问。
# app/workers
class AwesomeWorker
include Sidekiq::Worker
def perform
RandomNumberModel.create! { random_number: Random.new.rand(1..100) }
end
end