更新的CSS样式表在部署到Heroku后未加载? [英] Updated CSS Stylesheet not loaded following deployment to Heroku?

查看:130
本文介绍了更新的CSS样式表在部署到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文件

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.

感谢您的时间。

编辑:

认为我现在知道问题是什么。我的样式表从不更新到我的公共/资产文件夹。我不知道我能做些什么让他们出现在那里。

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仓库中添加了资产预编译文件。理想情况下,它不应该在那里,因为heroku可以为你每当你 push 它。

It looks like you have added assets precompiled file in your git repo. Ideally, it shouldn't be there since heroku can this for you whenever you push it.

,你必须这样做


  1. git rm -r public / assets / / li>
  2. .gitignore 文件中添加 public / assets / ** li>
  3. git add。

  4. git commit -amallow heroku auto asset precompilation

  5. git push heroku master

  1. git rm -r public/assets/
  2. add public/assets/** in your .gitignore file
  3. git add .
  4. git commit -am "allow heroku auto assets precompilation"
  5. git push heroku master

这篇关于更新的CSS样式表在部署到Heroku后未加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆