The Rails Asset Pipeline guide instructs you to use config.assets.paths
in config/application.rb
but I don't have access to the request's subdomain at this point.
I'd like to be able to prepend an extra path (for the current request only) based on the request's subdomain.
My application specific details
It's a basic CMS app. The root domain.com
host handles the administrative part with standard controller/view rendering and default asset paths.
Requests to subdomain.domain.com
renders the site based on subdomain
. It calls prepend_view_path
in a before_filter
and adds Rails.root.join('vendor/sites/[subdomain]/templates')
for the current request only.
I'd like to be able to prepend Rails.root.join('vendor/sites/[subdomain]/assets')
to the Sprockets search paths when the request host is [subdomain].domain.com
.
EDIT
I ended up just dropping in a mixin for Sprockets::Environment
that overwrites the call method:
module SiteAssetsResolver
def call(env)
begin
# prepend path based on subdomain (from env)
super # Sprockets::Server#call
ensure
# remove path based on subdomain
end
end
end
MyApp::Application.assets.extend(SiteAssetsResolver)