17
votes

Here is the app/assets/ for a Rails 4.2 app.

enter image description here

There are 3 bootstraps js and css files. After deploying to production (ubuntu 12.1), assets precompile was done on server (deployed under suburi):

RAILS_ENV=production bundle exec rake assets:precompile RAILS_RELATIVE_URL_ROOT=/mysuburi

Here is the production.rb:

  config.cache_classes = true
  config.eager_load = true
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true
  config.serve_static_files = false #ENV['RAILS_SERVE_STATIC_FILES'].present?
  config.assets.compress = true
  config.assets.js_compressor = :uglifier
  config.assets.compile = false
  config.assets.digest = true
  config.log_level = :debug
  config.i18n.fallbacks = true
  config.active_support.deprecation = :notify
  config.log_formatter = ::Logger::Formatter.new
  config.active_record.dump_schema_after_migration = false

Here is the head of application.css.scss:

@import "bootstrap.min.css";
@import "bootstrap-theme.min.css";

@import "simple_form.css.scss";
@import "user_menus.css.scss";

In application.js, it has:

//= require bootstrap.min

Here is the output of ls for public/assets/ on production server:

application-05cf37813d76c2bd659271403789374cc118f1a4e616ec220969577b79ff6514.css
application-375b4b5d8fc285716f4fdca966aa960912efe8292242df8f1a60b99d5caa4b02.js
authentify
banquet_coursex
banquetx
biz_workflowx
commonx
glyphicons-halflings-regular-5d234508037dc13a419ef6ce48f3fc73dbb477f1a162c052b872182b494e626e.svg
glyphicons-halflings-regular-bd18efd3efd70fec8ad09611a20cdbf99440b2c1d40085c29be036f891d65358.ttf
glyphicons-halflings-regular-f495f34e4f177cf0115af995bbbfeb3fcabc88502876e76fc51a4ab439bc8431.eot
glyphicons-halflings-regular-fc969dc1c6ff531abcf368089dcbaf5775133b0626ff56b52301a059fc0f9e1e.woff
jquery-ui
searchx
state_machine_logx
user_manualx
user_menus-7c46e17f4172c2a954eeaf85e80b4e030d1ed0fb3927288bbe07eeb4fb8cbfc5.css

By comparing with other Rails app, it is missing manifest.json under /assets. We tried various config options in config/environment/production.rb with no avail. The only option works on production server is live compilation of config.assets.compile = true (not recommended). What is wrong with our code to cause assets precompile failing?

UPDATE: we have re-built the Rails app from ground up and the assets problem remains the same. This assets precompile issue may have nothing to do with setup in config/production.rb' and 'config/initializers/aseets.rb as we suspect. Rolling back version of bundler and rake did not help. The same bootstrap css and js files have been used in another Rails 4.2 app running on the same production server without the problem.

3
We don't have to do config.assets.precompile += ['bootstrap.min.js', 'b... for assets in side app/assets. This only need for external assets unless not specified in manifesto.maximus ツ
@maximus, yes,not including those css or js file explicitly in assets.rb was what we did for another Rails 4.2 app which has exactly the same css and bootstrap assets. But not with this app. If those bootstrap js/css are not included, then they are not fingerprinted at all after assets precompile.user938363
@ Mauricio Gracia , yes, but this problem may be different. In our case, there is no error in assets precompile. The problem only shows when login to the website and open a page. Also if set config.assets.compile = true (so called live compilation. may have poor performance) in production.rb, then the assets shows correctly on page.user938363
Let me come forward asking question one by one: 1. what process you are using for deployment?Rubyrider

3 Answers

18
votes

If you're using sprockets 3.x, the manifest file is now named .sprockets-manifest-md5hash.json, it is stated in the Upgrading Guide

0
votes

I presume you include these JS and CSS files in your application HTML template explicitly?

They won't magically end up compiled into the main application CSS and JS file, and you need to make sure that you use the tag helpers, not direct paths, when referencing them from HTML erb files.

When in doubt, use asset_path.

0
votes

The manifestxxx.json file is generated after rolling back version of sprockets to 2.12.3 from 3.2.0. The problem was caused by too-new version of gem sprockets which is used to precompile assets.