gpt4 book ai didi

ruby-on-rails - Assets 在隔离的引擎端点中不起作用

转载 作者:行者123 更新时间:2023-12-03 21:35:28 24 4
gpt4 key购买 nike

尝试访问作为中间件端点安装的独立引擎内的 Assets 时,我收到 Not Found 错误。我正在尝试从引擎内部访问 Assets ,因此应该能够找到它们。

我怀疑 Assets 路由不起作用,因为我将某个域上的请求路由到端点的方式:

require 'addressable/uri'

class AdminRouter

def initialize(app)
@app = app
end

def call(env)
request = ActionDispatch::Request.new(env)

# Allow requests to the admin system through without going any further
if request.host == Rails.application.config.admin_address
Admin::Engine.call(env)
else
@app.call(env)
end
end

end

我这样做是因为我不希望从主应用程序访问管理应用程序路由,反之亦然。它运行良好,只是 Assets 不行。

最佳答案

看起来没有这样的 Assets 中间件。 action_pack循环遍历每个 Assets 并在主路由器中添加一条指向机架端点的路由:

/gems/actionpack-3.2.22.2/lib/sprockets/bootstrap.rb 

app.routes.prepend do
mount app.assets => config.assets.prefix
end

/gems/sprockets-2.2.3/lib/sprockets/server.rb

这反过来又为 Assets 服务。

所以我的原因 Admin::Engine无法访问路线是因为它们在应用程序启动时从未被添加。

我的解决方法是使用 asset_host为 Assets 服务器指定一个特殊的主机名。然后我将对该主机的请求路由到主应用程序而不是管理引擎。

关于ruby-on-rails - Assets 在隔离的引擎端点中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35952799/

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