找不到文件 affix.js

could not find file affix.js

当我推送到 Heroku 时,预编译资产出现问题,安装了 Bootstrap,但找不到文件 'affix.js'。 我尝试添加:

 //= require bootstrap/affix

但这并没有帮助,有人遇到同样的问题吗?

我过去几次遇到过这个问题,通常会更新 bootstrap 修复它。这次不是:

GEMFILE:
# Assets
gem 'bootstrap-sass', '~> 3.3.5'
gem 'sass-rails', '>= 3.2'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'font-awesome-sass'
gem 'nprogress-rails'

ERROR:
remote: rake aborted!
remote: Sprockets::FileNotFound: could not find file: 
/tmp/build_7160395b09b71ebb83ef5bf51eb32d75/vendor/bundle/ruby/2.2.0/gems/bootstrap-sass-3.3.5.1/assets/javascripts/bootstrap/affix.js          remote:tmp/build_2e50ddbbbfb3469acb16fa727d62c302/vendor/bundle/ruby/2.2.0/gems/sprockets-3.3.2/lib/sprockets/loader.rb:95:in `load_from_unloaded'

远程:/tmp/build_2e50ddbbbfb3469acb16fa727d62c302/vendor/bundle/ruby/2.2.0/gems/sprockets-3.3.2/lib/sprockets/loader.rb:60:in block in load' remote:/tmp/build_2e50ddbbbfb3469acb16fa727d62c302/vendor/bundle/ruby/2.2.0/gems/sprockets-3.3.2/lib/sprockets/loader.rb:286:infetch_asset_from_dependency_cache'

好的,这成功了:

rake assets:precompile

git add .
git commit -m "precompile all assets"
git push heroku-or-whatever-branch

虽然我仍然无法解释任何事情...

您的资产可能在之前的部署中一团糟。要重置资产并在 heroku 上开始干净的预编译,请在 config/initializers/assets.rb 文件中增加 Rails.application.config.assets.version。

Rails.application.config.assets.version = '1.1'