我在哪里可以找到 Rails 个职位的域设置?

Where can I find domain settings for Rails jobs?

我在 Rails 5.2 尝试通过 ActiveJob 发送消息。一切都很好,但是当我尝试使用助手(如 image_tag(user.avatar, class: "avatar"))为作业方法中的图像制作 url 时,它将 url 的域设置为“http://example.org ".

其他 Rails 部分使用了正确的名称,但作业似乎从配置文件中检索了默认设置(我猜)。

你能告诉我在哪里可以找到它吗?或者也许我必须在配置中的某处放置一条魔法线?

提前致谢!

在您的环境配置中定义默认主机:

# config/environments/staging.rb
MyApp::Application.configure do
  # ...
  Rails.application.routes.default_url_options[:host] = 'preview.mydomain.com'
  Rails.application.routes.default_url_options[:protocol] = 'https'
  # ...
end

在你的工作中加入 URL 帮手 class:

class MyJob
  include Rails.application.routes.url_helpers

  def perform(*args)
    # your image tage goes here
  end
end