在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
我
NameError:未定义的局部变量或方法`app'for
如何在Rails的ActiveJob中使用app
?
答案 0 :(得分:1)
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