部署到 Heroku 后未加载更新的 CSS 样式表? [英] Updated CSS Stylesheet not loaded following deployment to Heroku?
问题描述
这对我来说已经有一段时间了,但我仍然无法弄清楚在 Rails 4 中资产管道是如何工作的.我终于学会了如何预编译资产,但再次部署后,我的 CSS样式表未更新.
This has been a problem for me for a while now, but I still can't figure out how the asset pipeline works in Rails 4. I finally learned how to pre-compile assets, but once again after deployment, my CSS Stylesheet isn't getting updated.
我通过转到开发人员工具并查看源代码确认了这一点.它看起来与我的 CSS 文件不同.我的猜测是问题出在我的 production.rb 文件中.
I confirmed this by going to Developer Tools and viewing the source. It looks different from my CSS files. My guess is the problem lies in my production.rb file.
Production.rb
Games::Application.configure do
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_assets = true
config.assets.js_compressor = :uglifier
config.assets.compile = true
config.assets.digest = true
config.assets.version = '1.0'
config.log_level = :info
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.log_formatter = ::Logger::Formatter.new
end
Application.rb
require File.expand_path('../boot', __FILE__)
require 'rails/all'
Bundler.require(*Rails.groups)
module Games
class Application < Rails::Application
config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif)
config.exceptions_app = self.routes
end
end
这是我的 Application.html.erb 文件和助手.
Here is my Application.html.erb file with the helpers.
<!DOCTYPE html>
<html>
<head>
<title><%= @title %></title>
<%= stylesheet_link_tag "application", media: "all",
"data-turbolinks-track" => true %>
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
<%= render 'layouts/footer' %>
</body>
</html>
宝石文件
gem 'rails', '4.0.4'
group :development, :test do
gem 'sqlite3', '1.3.8'
gem 'rspec-rails', '2.13.1'
end
group :production do
gem 'pg', '0.17.1'
gem 'rails_12factor'
end
group :test do
gem 'selenium-webdriver', '2.35.1'
gem 'capybara', '2.1.0'
end
gem 'sass-rails', '~> 4.0.2'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'sprockets-rails', '~> 2.0.0'
gem 'bootstrap-sass', '2.3.2.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 1.2'
这是我采取的步骤
heroku run rake assets:precompile RAILS_ENV=production
git add .
git commit
git push heroku master
现在,也许我错了,但是运行了 git add .(意味着添加所有文件)它也应该加载最新的样式表.但再一次,Heroku 似乎失败了.
Now, maybe I'm mistaken, but having run the git add . (meaning add all files) it should have loaded the latest stylesheet as well. But once again, it seems like Heroku failed.
这种情况以前发生过,而且越来越烦人,所以我想为此找到一个解释.
This has happened before, and is getting annoying, so I would like to find an explanation for this.
感谢您的宝贵时间.
我想我现在知道问题所在了.我的样式表永远不会更新到我的 public/assets 文件夹.我不知道我该怎么做才能让它们出现在那里.
I think I now know what the problem is. My stylesheets never get updated to my public/assets folder. I don't know what I can do to make them appear there.
推荐答案
看起来你已经在你的 git repo 中添加了资产预编译文件.理想情况下,它不应该存在,因为只要您push
,heroku 就可以为您执行此操作.
It looks like you have added assets precompiled file in your git repo. Ideally, it shouldn't be there since heroku can do this for you whenever you push
it.
要解决这个问题,你必须这样做
To fix this, you have to do this
git rm -r public/assets/
- 在您的
.gitignore
文件中添加public/assets/**
git add .
git commit -am "允许 heroku 自动资产预编译"
git push heroku master
git rm -r public/assets/
- add
public/assets/**
in your.gitignore
file git add .
git commit -am "allow heroku auto assets precompilation"
git push heroku master
这篇关于部署到 Heroku 后未加载更新的 CSS 样式表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!