I came up with this rather simple solution: add a controller action that proxies the file. Seems to work great! Obviously it only works with precompiled files so run rake assets:precompile to test in development.
# config/routes.rb
get "integrations/assets/:id", to: "assets#show"
# app/controllers/assets_controller.rb
class AssetsController < ApplicationController
skip_before_filter :verify_authenticity_token, only: [:show]
def show
file_name = "#{params[:id]}.#{params[:format]}"
asset_path = ActionController::Base.helpers.asset_path(file_name)
file_path = "#{Rails.root}/public#{asset_path}"
mime_type = Mime::Type.lookup_by_extension(params[:format])
send_file(file_path, type: mime_type, disposition: "inline")
end
end
I came up with this rather simple solution: add a controller action that proxies the file. Seems to work great! Obviously it only works with precompiled files so run
rake assets:precompile
to test in development.Posting here as a different solution to https://github.com/rails/sprockets-rails/issues/49 because that thread is locked.