导轨 4.X
它在 Rails 4.X 上不起作用,一个可能的(肮脏的)解决方法是:
require 'sprockets/railtie'
Bundler.require(:default, Rails.env)
module Sprockets
module Paths
SKIP_GEMS = ["rails-assets-jquery", "rails-assets-bootstrap"]
def append_path_with_rails_assets(path)
append_path_without_rails_assets(path) unless SKIP_GEMS.any? { |gem| path.to_s.start_with?(Gem.loaded_specs[gem].full_gem_path) }
end
alias_method_chain :append_path, :rails_assets
end
end
Rails 5.X 更新
alias_method_chain
自 Rails 5.X 起已弃用。这是使用的更新版本prepend
,并覆盖了Sprockets::Environment
模块而不是Sprockets::Paths
.
module SprocketsPathsOverride
SKIP_GEMS = ["rails-assets-jquery", "rails-assets-bootstrap"]
def append_path(path)
should_skip = SKIP_GEMS.any? do |gem|
path.to_s.start_with?(Gem.loaded_specs[gem].full_gem_path)
end
super(path) unless should_skip
end
end
Sprockets::Environment.prepend(SprocketsPathsOverride)