[英]Rails routes for non-standard assets in a mountable engine
I have a few non-standard assets (ie files that are not images/javascript files/stylesheets such as json and binary files) that live within a mountable engine (without isolate_namespace
) in app/assets/data
. 我有一些非标准资产(即不是图像/ javascript文件/样式表的文件,如json和二进制文件),
isolate_namespace
位于app/assets/data
的可安装引擎(没有isolate_namespace
) app/assets/data
。 I want these to be part of the asset pipeline (in the same way as eg images). 我希望这些成为资产管道的一部分(与图像相同)。 I can add them to the asset paths collection, eg
我可以将它们添加到资产路径集合中,例如
class Engine < ::Rails::Engine
config.after_initialize do
Rails.application.config.assets.paths << root.join("app", "assets", "data")
end
end
and I can see in the Rails console that the assets are visible to the asset pipeline (eg via Rails.application.assets[]
and ActionController::Base.helpers.asset_path
). 我可以在Rails控制台中看到资产对资产管道是可见的(例如通过
Rails.application.assets[]
和ActionController::Base.helpers.asset_path
)。 For instance, for a file app/assets/data/foo.json
, the asset_path
helper in the rails console for the hosting app gives me a path assets/foo.json
, however that path does not work, I get a 例如,对于文件
app/assets/data/foo.json
,主机应用程序的rails控制台中的asset_path
帮助程序为我提供了路径assets/foo.json
,但是该路径不起作用,我得到了一个
ActionController::RoutingError (No route matches [GET] "/assets/foo.json")
error. 错误。
How can I get the hosting Rails app to serve these files? 如何获得托管Rails应用程序来提供这些文件?
Turns out, this is some odd behavior with json files with specific names. 事实证明,这是json文件具有特定名称的一些奇怪行为。 The files in question are named something like
schema-[UUID].json
. 有问题的文件的名称类似于
schema-[UUID].json
。 Rails seems to think these are calls to some controller (even though there is no such route, nor a schema
controller) that want json-formatted data back. Rails似乎认为这些是对某些控制器的调用(即使没有这样的路由,也没有
schema
控制器)需要json格式的数据。 When I rename the files to [UUID]-schema.json
, they all of a sudden work. 当我将文件重命名为
[UUID]-schema.json
,它们突然工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.