Rails Asset Pipeline guide指导您在
我想能够基于请求的子域名为当前请求添加额外的路径(仅限当前请求)。 我的应用程序特定细节 这是一个基本的CMS应用程序。根
对
当请求主机为
config/application.rb
中使用config.assets.paths
,但此时我无法访问请求的子域。我想能够基于请求的子域名为当前请求添加额外的路径(仅限当前请求)。 我的应用程序特定细节 这是一个基本的CMS应用程序。根
domain.com
主机处理标准控制器/视图呈现和默认资产路径的管理部分。对
subdomain.domain.com
的请求基于subdomain
呈现站点。它在before_filter
中调用prepend_view_path
并为当前请求添加Rails.root.join('vendor/sites/[subdomain]/templates')
。当请求主机为
[subdomain].domain.com
时,我想能够将Rails.root.join('vendor/sites/[subdomain]/assets')
前置到Sprockets搜索路径中。
编辑
最终,我只是放入了一个Sprockets::Environment
的mixin,覆盖了call方法: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)