Reputation: 163
I have a few non-standard assets (i.e. 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
. I want these to be part of the asset pipeline (in the same way as e.g. images).
I can add them to the asset paths collection, e.g.
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 (e.g. via Rails.application.assets[]
and 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
ActionController::RoutingError (No route matches [GET] "/assets/foo.json")
error.
How can I get the hosting Rails app to serve these files?
Upvotes: 3
Views: 665
Reputation: 163
Turns out, this is some odd behavior with json files with specific names. The files in question are named something like 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. When I rename the files to [UUID]-schema.json
, they all of a sudden work.
Upvotes: 1