gpt4 book ai didi

ruby-on-rails - Rails - 如何在 ActiveJob 中使用 ActionDispatch::Integration::Session

转载 作者:行者123 更新时间:2023-12-02 03:44:41 26 4
gpt4 key购买 nike

在 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: undefined local variable or method `app' for

如何在 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

关于ruby-on-rails - Rails - 如何在 ActiveJob 中使用 ActionDispatch::Integration::Session,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47186698/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com