微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

部署到Heroku后未加载更新的CSS样式表?

这对我来说已经有一段时间了,但是我仍然无法弄清楚Rails 4中的资产管道是如何工作的.我终于学会了如何预编译资产,但是在部署之后,我的CSS样式表再次没有了得到更新.

我通过访问开发人员工具并查看源来确认了这一点.它看起来与我的CSS文件不同.我的猜测是问题在于我的production.rb文件.

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文件和帮助程序.

<!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失败了.

这种情况以前发生过,而且越来越烦人,所以我想找到解释.

感谢您的时间.

编辑:

我想我现在知道问题是什么了.我的样式表永远不会更新到我的public / assets文件夹.我不知道我能做些什么才能让它们出现在那里.

解决方法

看起来您已在git仓库中添加了资产预编译文件.理想情况下,它不应该存在,因为heroku可以在你推动时为你做这件事.

解决这个问题,你必须这样做

> git rm -r public / assets />在.gitignore文件添加public / assets / **> git add.> git commit -am“允许heroku汽车资产预编译”> git push heroku master

原文地址:https://www.jb51.cc/css/217503.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。