发生在我身上&我的同事忘了在预编译文件列表中添加.js
或.css
。我想更改production.rb
文件以扫描javascripts / stylesheets文件夹,并动态添加到config.assets.precompile
变量。代码看起来像这样:
def get_assets(folder,select_extensions,delete_from,remove_extensions)
files = Dir["#{folder}/**/*"].select {|e| select_extensions.include?(File.extname(e))}
basenames = files.map {|e| e.sub(/.*#{delete_from}\//,"") }
basenames.each do |bn|
remove_extensions.each do |ext|
bn.sub!(ext,"")
end
end
basenames
end
在production.rb中,我会有类似的东西:
config.assets.precompile = get_assets("#{Rails.root}/app/assets/javascripts",[".js",".coffee"],"javascripts",[".coffee"]) + get_assets("#{Rails.root}/app/assets/stylesheets",[".css",".scss"],"stylesheets",[".scss"])
你认为我的想法存在任何缺点/陷阱吗?