Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails asset paths missing fingerprint in production

We've just deployed a Rails 4.0.3 app to production and have found that asset paths generated by stylesheet_link_tag and javascript_link_tag are missing their fingerprints. So instead of requesting something like application-c841bd1c82c25bb1de8452d2338479f7.js, the page is just request application.js.

RAILS_ENV=production bundle exec rake assets:precompile is successful and generates fingerprinted files.

The bits from config/environments/production.rb that seem relevant are:

# Compress JavaScripts and CSS
config.assets.compress = true

# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false

# Generate digests for assets URLs
config.assets.digest = true

# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = false

This is running on our own Apache server, not Heroku. I've looked around quite a bit and found similar problems, but none of the troubleshooting steps for those are helping here. Thanks.

More Information

In case it is helpful, here are the full contents (commented lines removed) of our config files:

application.rb

require File.expand_path('../boot', __FILE__)

require 'rails/all'

if defined?(Bundler)
  # If you precompile assets before deploying to production, use this line
  Bundler.require(*Rails.groups(:assets => %w(development test)))
  # If you want your assets lazily compiled in production, use this line
  # Bundler.require(:default, :assets, Rails.env)
end

module Ctrc
  class Application < Rails::Application
    config.ceal.application_title = "CTRC Budgeting"

    config.encoding = "utf-8"

    config.filter_parameters += [:password]

    config.active_support.escape_html_entities_in_json = true

    config.assets.enabled = true
    config.assets.version = '1.0'

    config.pmacs_redmine.project_identifier = 'itmat-gcrc'

    config.app_data_path = '/data/web/apps/itmat/ctrc'
    config.paperclip_defaults = {
      path: "/data/web/apps/itmat/ctrc/:attachment/:id/:style/:basename.:extension"
    }

    if ENV['RAILS_RELATIVE_URL_ROOT']
      config.assets.prefix = ENV['RAILS_RELATIVE_URL_ROOT'] + '/assets'
    end
  end
end

production.rb

Ctrc::Application.configure do
  config.cache_classes = true

  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true

  config.serve_static_assets = false
  config.assets.compress = true
  config.assets.compile = false
  config.assets.digest = true

  config.i18n.fallbacks = true

  config.active_support.deprecation = :notify

  config.eager_load = true

end

I know that the application is running in production mode because if I set

config.assets.compile = true

in that file, the CSS and JavaScript are compiled and requested correctly.

I'm including those assets in the page like so:

<%= stylesheet_link_tag    "application", media: "all" %>
<%= javascript_include_tag "application" %>

but it is still generating links to those assets like this:

<link href="/apps/itmat/ctrc/stylesheets/application.css" media="all" rel="stylesheet">
<script src="/apps/itmat/ctrc/javascripts/application.js"></script>

instead of the fingerprinted links I would expect to see.

like image 613
barendt Avatar asked Jul 08 '14 19:07

barendt


1 Answers

I had a similar issue and it turned out to be a problem with the gem AssetSync. Either setting config.assets.compile = true or removing the gem resolved the issue. Compiling assets on the fly and having your Rails serve your assets might be acceptable if you're using a CDN, but generally, taking another approach is usually recommended.

like image 135
Tuuli Pöllänen Avatar answered Sep 25 '22 03:09

Tuuli Pöllänen