在 Rails 的控制台中,app
定义为
[1] pry(main)> app
=> #<ActionDispatch::Integration::Session:0x000000189028e8
现在,我有一个简单的工作,比如:
class MyJob < ActiveJob::Base
queue_as :low
def perform
app.get('/my/path', nil, {'Accept-Language' => "it"})
end
end
如果我打电话给MyJob.perform_now
我得到
名称错误:未定义的局部变量或方法"app"
如何在 Rails 的 ActiveJob 中使用app
?
class MyJob < ActiveJob::Base
queue_as :low
def perform
app = ActionDispatch::Integration::Session.new(Rails.application)
app.get('/my/path', nil, {'Accept-Language' => "it"})
end
end