Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
729 views
in Technique[技术] by (71.8m points)

ruby on rails - Updated CSS Stylesheet not loaded following deployment to Heroku?

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.

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

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 File

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'

Here are the steps I've taken

heroku run rake assets:precompile RAILS_ENV=production
git add .
git commit
git push heroku master

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.

Thank you for your time.

Edit:

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

  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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...