Production environment not referencing fingerprinted asssets

39 Views Asked by At

An asset is called in a view as <%= image_tag('union_15') %>

In development mode the HTML generated is correct and renders as expected:
<img src="/assets/union_15-2bd9d905e662bcd012424ffda847b1125dc8637a0b8cee101a174f9db26e838d.png">

There is an entry for config/initializers/assets.rb
Rails.application.config.assets.precompile += %w( initialise.css pdf.css )

environments/production.rb has config.public_file_server.enabled = true set as per the rails guides.

RAILS_ENV=production rails assets:precompile was run locally AND on the server.
In addition .gitignore was adjusted by commenting # /public/assets to ensure the precompiled assets gets percolated to the server.

The deployment process does execute with capistrano in production:

      01 $HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile
    ✔ 01 [email protected] 3.541s
00:34 deploy:assets:backup_manifest
      01 mkdir -p /home/rd/app_name/releases/20231219091853/assets_manifest_backup

On the production server the following file was examined
current/assets_manifest_backup/.sprockets-manifest-e4c8157abe8d8b5916786c943a01c388.json
to ascertain that the fingerprinting is occuring. The following JSON entry is found:
[...]"union_15-2bd9d905e662bcd012424ffda847b1125dc8637a0b8cee101a174f9db26e838d.png":{"logical_path":"union_15.png","mtime":"2023-12-19T09:19:21+00:00","size":2233,"digest":"88b013210661a0b48a30e59ec033c2add1a069ccb72d1d2ce49f9f2c9531963b","integrity":"sha256-iLATIQZhoLSKMOWewDPCrdGgacy3LR0s5J+fLJUxljs="},[...]

Yet, in production, the HTML does not reference properly, rendering:
<img src="/images/union_15" />

This is unexpected given the rails convention. What is wrong/missing here in the setup?

1

There are 1 best solutions below

0
Jerome On

It turns out two configurations were off-base. The following set the servicing back on course... The environment variable was non-existent, compilation needed to be set to true.

#  config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present?
  config.public_file_server.enabled = true
  config.assets.compile = true