Rails 在生产中提供旧的 css 文件

Rails serves old css file in production

在我的申请中css我有:

.red {
  background-color: #F48585 !important;
}

然后我删除了这些样式。然后我将我的应用程序部署到 heroku, 所以我做了

git add -A
git commit -m "message"
git push heroku master
heroku run bundle 
heroku run rake db:setup

我的应用程序已部署,基础框架的样式等工作正常。但我仍然定义了 .red class 样式。而且所有新样式都被忽略,似乎 rails 服务器旧 css 文件。 我所有的样式资产都预编译到一个文件中 application.scss.

您刚刚忘记了 1 个步骤:

git 添加-A

git commit -m "message"

git push origin your-git-branch

git 推送 heroku 大师

在最后一条命令之后,heroku 将自动 运行 捆绑安装并在生产模式下为 运行 设置你的 project/app。

你好像忘了预编译你的资产。请注意,只有当您的存储库中没有 public/assets/manifest.yml 文件时,heroku 才会自动预编译资产,否则它会认为您正在本地编译您的资产。参见:https://devcenter.heroku.com/articles/rails-asset-pipeline#compiling-assets-locally

除此之外,如果您想在部署时预编译资产,同时删除 public/assets 文件夹的内容,您应该记住 heroku 将存储预编译为临时文件,最终会被删除,因此您的生产应用程序不能依赖这些预编译文件。

所以对于你目前的情况,你有主要和高级两个选项:

  1. 在本地预编译您的资产 bundle exec rake assets:precompile 并将结果提交到 repo。 (现在更快)
  2. 使用类似 https://github.com/rumblelabs/asset_sync 的 gem 并在部署时预编译资产,但将结果存储在第 3 方云存储中。

我找到了这个解决方案,rake tmp:clear