Rails 7.1 (Ruby 3.2) assets 404 response, no css, no javascript

First of all, English is not my native language, for which I apologize in advance.

I can’t get my app to load CSS and Javascript, everything works in local (development and production).

The error returns the following log:

2024-03-19T05:01:38Z proxy[e824277a752158] ams [info]Starting machine
2024-03-19T05:01:38Z app[e824277a752158] ams [info][    0.055675] Spectre V2 : WARNING: Unprivileged eBPF is enabled with eIBRS on, data leaks possible via Spectre v2 BHB attacks!
2024-03-19T05:01:38Z app[e824277a752158] ams [info][    0.058878] PCI: Fatal: No config space access function found
2024-03-19T05:01:38Z app[e824277a752158] ams [info] INFO Starting init (commit: 913ad9c)...
2024-03-19T05:01:38Z app[e824277a752158] ams [info] INFO Preparing to run: `/rails/bin/docker-entrypoint ./bin/rails server` as 1000
2024-03-19T05:01:38Z app[e824277a752158] ams [info] INFO [fly api proxy] listening at /.fly/api
2024-03-19T05:01:38Z app[e824277a752158] ams [info]2024/03/19 05:01:38 listening on [fdaa:8:bf51:a7b:246:32a9:42ea:2]:22 (DNS: [fdaa::3]:53)
2024-03-19T05:01:38Z runner[e824277a752158] ams [info]Machine started in 648ms
2024-03-19T05:01:39Z proxy[e824277a752158] ams [info]machine started in 1.719896299s
2024-03-19T05:01:41Z app[e824277a752158] ams [info]=> Booting WEBrick
2024-03-19T05:01:41Z app[e824277a752158] ams [info]=> Rails 7.1.3.2 application starting in production http://0.0.0.0:3000
2024-03-19T05:01:41Z app[e824277a752158] ams [info]=> Run `bin/rails server --help` for more startup options
2024-03-19T05:01:43Z app[e824277a752158] ams [info][2024-03-19 05:01:43] INFO  WEBrick 1.8.1
2024-03-19T05:01:43Z app[e824277a752158] ams [info][2024-03-19 05:01:43] INFO  ruby 3.2.0 (2022-12-25) [x86_64-linux]
2024-03-19T05:01:43Z app[e824277a752158] ams [info][2024-03-19 05:01:43] INFO  WEBrick::HTTPServer#start: pid=305 port=3000
2024-03-19T05:01:43Z proxy[e824277a752158] ams [info]machine became reachable in 4.079785536s
2024-03-19T05:01:44Z app[e824277a752158] ams [info]172.16.32.114 - - [19/Mar/2024:05:01:43 UTC] "GET / HTTP/1.1" 302 0
2024-03-19T05:01:44Z app[e824277a752158] ams [info]https://gestor-legal.fly.dev/apuntes -> /
2024-03-19T05:01:44Z proxy[1781949bd42e98] ams [info]Starting machine
2024-03-19T05:01:44Z app[1781949bd42e98] ams [info][    0.035097] PCI: Fatal: No config space access function found
2024-03-19T05:01:44Z app[1781949bd42e98] ams [info] INFO Starting init (commit: 913ad9c)...
2024-03-19T05:01:44Z app[1781949bd42e98] ams [info] INFO Preparing to run: `/rails/bin/docker-entrypoint ./bin/rails server` as 1000
2024-03-19T05:01:44Z app[1781949bd42e98] ams [info] INFO [fly api proxy] listening at /.fly/api
2024-03-19T05:01:44Z app[1781949bd42e98] ams [info]2024/03/19 05:01:44 listening on [fdaa:8:bf51:a7b:a27f:cc7f:400e:2]:22 (DNS: [fdaa::3]:53)
2024-03-19T05:01:44Z runner[1781949bd42e98] ams [info]Machine started in 416ms
2024-03-19T05:01:45Z proxy[1781949bd42e98] ams [info]machine started in 1.420260134s
2024-03-19T05:01:46Z app[1781949bd42e98] ams [info]=> Booting WEBrick
2024-03-19T05:01:46Z app[1781949bd42e98] ams [info]=> Rails 7.1.3.2 application starting in production http://0.0.0.0:3000
2024-03-19T05:01:46Z app[1781949bd42e98] ams [info]=> Run `bin/rails server --help` for more startup options
2024-03-19T05:01:48Z app[1781949bd42e98] ams [info][2024-03-19 05:01:48] INFO  WEBrick 1.8.1
2024-03-19T05:01:48Z app[1781949bd42e98] ams [info][2024-03-19 05:01:48] INFO  ruby 3.2.0 (2022-12-25) [x86_64-linux]
2024-03-19T05:01:48Z app[1781949bd42e98] ams [info][2024-03-19 05:01:48] INFO  WEBrick::HTTPServer#start: pid=305 port=3000
2024-03-19T05:01:48Z proxy[1781949bd42e98] ams [info]machine became reachable in 2.54866219s
2024-03-19T05:01:48Z app[1781949bd42e98] ams [info]172.16.153.250 - - [19/Mar/2024:05:01:48 UTC] "GET /dashboard HTTP/1.1" 200 10527
2024-03-19T05:01:48Z app[1781949bd42e98] ams [info]https://gestor-legal.fly.dev/apuntes -> /dashboard
2024-03-19T05:01:48Z app[1781949bd42e98] ams [info]172.16.153.250 - - [19/Mar/2024:05:01:48 UTC] "GET /assets/application-75c92e9aade8f9197e7641b75503e4349b33f95c1dc51ad45a51c31037960cc2.css HTTP/1.1" 404 1722
2024-03-19T05:01:48Z app[1781949bd42e98] ams [info]https://gestor-legal.fly.dev/dashboard -> /assets/application-75c92e9aade8f9197e7641b75503e4349b33f95c1dc51ad45a51c31037960cc2.css
2024-03-19T05:01:48Z app[1781949bd42e98] ams [info]172.16.153.250 - - [19/Mar/2024:05:01:48 UTC] "GET /assets/tinymce-a32517da06b217cfb79c72a22cd7c29d7dfecd23ddf4d7ef26c7deec3f957362.js HTTP/1.1" 404 1722
2024-03-19T05:01:48Z app[1781949bd42e98] ams [info]https://gestor-legal.fly.dev/dashboard -> /assets/tinymce-a32517da06b217cfb79c72a22cd7c29d7dfecd23ddf4d7ef26c7deec3f957362.js
2024-03-19T05:01:48Z app[1781949bd42e98] ams [info]172.16.153.250 - - [19/Mar/2024:05:01:48 UTC] "GET /assets/turbo.min-918a6cf2f2be8ed9555c9a11eee69c7dc2f01770802815576efc931876b327fb.js HTTP/1.1" 404 1722
2024-03-19T05:01:48Z app[1781949bd42e98] ams [info]https://gestor-legal.fly.dev/dashboard -> /assets/turbo.min-918a6cf2f2be8ed9555c9a11eee69c7dc2f01770802815576efc931876b327fb.js
2024-03-19T05:01:48Z app[1781949bd42e98] ams [info]172.16.153.250 - - [19/Mar/2024:05:01:48 UTC] "GET /assets/stimulus.min-dd364f16ec9504dfb72672295637a1c8838773b01c0b441bd41008124c407894.js HTTP/1.1" 404 1722
2024-03-19T05:01:48Z app[1781949bd42e98] ams [info]https://gestor-legal.fly.dev/dashboard -> /assets/stimulus.min-dd364f16ec9504dfb72672295637a1c8838773b01c0b441bd41008124c407894.js
2024-03-19T05:01:48Z app[1781949bd42e98] ams [info]172.16.153.250 - - [19/Mar/2024:05:01:48 UTC] "GET /assets/stimulus-loading-3576ce92b149ad5d6959438c6f291e2426c86df3b874c525b30faad51b0d96b3.js HTTP/1.1" 404 1722
2024-03-19T05:01:48Z app[1781949bd42e98] ams [info]https://gestor-legal.fly.dev/dashboard -> /assets/stimulus-loading-3576ce92b149ad5d6959438c6f291e2426c86df3b874c525b30faad51b0d96b3.js
2024-03-19T05:01:48Z app[1781949bd42e98] ams [info]172.16.153.250 - - [19/Mar/2024:05:01:48 UTC] "GET /assets/Chart.bundle-c5bdf938fbc6fe19dcc4ce77047008b5686a04ceeae22ba312e3610aba0832e7.js HTTP/1.1" 404 1722
2024-03-19T05:01:48Z app[1781949bd42e98] ams [info]https://gestor-legal.fly.dev/dashboard -> /assets/Chart.bundle-c5bdf938fbc6fe19dcc4ce77047008b5686a04ceeae22ba312e3610aba0832e7.js
2024-03-19T05:01:48Z app[1781949bd42e98] ams [info]172.16.153.250 - - [19/Mar/2024:05:01:48 UTC] "GET /assets/controllers/application-368d98631bccbf2349e0d4f8269afb3fe9625118341966de054759d96ea86c7e.js HTTP/1.1" 404 1722
2024-03-19T05:01:48Z app[1781949bd42e98] ams [info]https://gestor-legal.fly.dev/dashboard -> /assets/controllers/application-368d98631bccbf2349e0d4f8269afb3fe9625118341966de054759d96ea86c7e.js
2024-03-19T05:01:48Z app[1781949bd42e98] ams [info]172.16.153.250 - - [19/Mar/2024:05:01:48 UTC] "GET /assets/controllers/index-2db729dddcc5b979110e98de4b6720f83f91a123172e87281d5a58410fc43806.js HTTP/1.1" 404 1722
2024-03-19T05:01:48Z app[1781949bd42e98] ams [info]https://gestor-legal.fly.dev/dashboard -> /assets/controllers/index-2db729dddcc5b979110e98de4b6720f83f91a123172e87281d5a58410fc43806.js
2024-03-19T05:01:48Z app[1781949bd42e98] ams [info]172.16.153.250 - - [19/Mar/2024:05:01:48 UTC] "GET /assets/chartkick-8eb76e6cbdb540d495739fce84049fd038e59e7fd55c9e08e47b0b5a74b62db4.js HTTP/1.1" 404 1722
2024-03-19T05:01:48Z app[1781949bd42e98] ams [info]https://gestor-legal.fly.dev/dashboard -> /assets/chartkick-8eb76e6cbdb540d495739fce84049fd038e59e7fd55c9e08e47b0b5a74b62db4.js
2024-03-19T05:01:48Z app[1781949bd42e98] ams [info]172.16.153.250 - - [19/Mar/2024:05:01:48 UTC] "GET /assets/trix-e17a480fcb4e30c8571f0fed42dc81de5faeef93755ca30fe9623eb3f5c709e5.js HTTP/1.1" 404 1722
2024-03-19T05:01:48Z app[1781949bd42e98] ams [info]https://gestor-legal.fly.dev/dashboard -> /assets/trix-e17a480fcb4e30c8571f0fed42dc81de5faeef93755ca30fe9623eb3f5c709e5.js
2024-03-19T05:01:48Z app[1781949bd42e98] ams [info]172.16.153.250 - - [19/Mar/2024:05:01:48 UTC] "GET /assets/application-fc3da7c15b02aed27365ac8c9f0461c3ac68aca4a62e71f8874f2a6d74dc5843.js HTTP/1.1" 404 1722
2024-03-19T05:01:48Z app[1781949bd42e98] ams [info]https://gestor-legal.fly.dev/dashboard -> /assets/application-fc3da7c15b02aed27365ac8c9f0461c3ac68aca4a62e71f8874f2a6d74dc5843.js
2024-03-19T05:01:48Z app[1781949bd42e98] ams [info]172.16.153.250 - - [19/Mar/2024:05:01:48 UTC] "GET /assets/actiontext-78de0ebeae470799f9ec25fd0e20ae2d931df88c2ff9315918d1054a2fca2596.js HTTP/1.1" 404 1722
2024-03-19T05:01:48Z app[1781949bd42e98] ams [info]https://gestor-legal.fly.dev/dashboard -> /assets/actiontext-78de0ebeae470799f9ec25fd0e20ae2d931df88c2ff9315918d1054a2fca2596.js
2024-03-19T05:01:48Z app[1781949bd42e98] ams [info]172.16.153.250 - - [19/Mar/2024:05:01:48 UTC] "GET /assets/controllers/hello_controller-549135e8e7c683a538c3d6d517339ba470fcfb79d62f738a0a089ba41851a554.js HTTP/1.1" 404 1722
2024-03-19T05:01:48Z app[1781949bd42e98] ams [info]https://gestor-legal.fly.dev/dashboard -> /assets/controllers/hello_controller-549135e8e7c683a538c3d6d517339ba470fcfb79d62f738a0a089ba41851a554.js

My Dockerfile:

# syntax = docker/dockerfile:1

# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile
ARG RUBY_VERSION=3.2.0
FROM ruby:$RUBY_VERSION-slim as base

LABEL fly_launch_runtime="rails"

# Rails app lives here
WORKDIR /rails

# Set production environment
ENV BUNDLE_DEPLOYMENT="1" \
    BUNDLE_PATH="/usr/local/bundle" \
    BUNDLE_WITHOUT="development:test" \
    RAILS_ENV="production"

# Update gems and bundler
RUN gem update --system --no-document && \
    gem install -N bundler

# Install packages needed to install nodejs
RUN apt-get update -qq && \
    apt-get install --no-install-recommends -y curl && \
    rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Install Node.js
ARG NODE_VERSION=21.5.0
ENV PATH=/usr/local/node/bin:$PATH
RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ && \
    /tmp/node-build-master/bin/node-build "${NODE_VERSION}" /usr/local/node && \
    rm -rf /tmp/node-build-master

# Throw-away build stage to reduce size of final image
FROM base as build

# Install packages needed to build gems
RUN apt-get update -qq && \
    apt-get install --no-install-recommends -y build-essential libpq-dev

# Build options
ENV PATH="/usr/local/node/bin:$PATH"

# Install application gems
COPY --link Gemfile Gemfile.lock ./
RUN bundle install && \
    bundle exec bootsnap precompile --gemfile && \
    rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git

# Copy application code
COPY --link . .

# Precompile bootsnap code for faster boot times
RUN bundle exec bootsnap precompile app/ lib/

# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile

# Final stage for app image
FROM base

# Install packages needed for deployment
RUN apt-get update -qq && \
    apt-get install --no-install-recommends -y curl postgresql-client nodejs && \
    rm -rf /var/lib/apt/lists /var/cache/apt/archives    

# Copy built artifacts: gems, application
COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}"
COPY --from=build /rails /rails

# Run and own only the runtime files as a non-root user for security
RUN groupadd --system --gid 1000 rails && \
    useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \
    chown -R 1000:1000 db log storage tmp
USER 1000:1000

# Entrypoint sets up the container.
ENTRYPOINT ["/rails/bin/docker-entrypoint"]

# Start the server by default, this can be overwritten at runtime
EXPOSE 3000
CMD ["./bin/rails", "server"]

My javascript/aplication.js

import "@hotwired/turbo-rails"
import "controllers"

import "popper"
import "bootstrap"

import "chartkick"
import "Chart.bundle"

var popoverTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="popover"]'))
var popoverList = popoverTriggerList.map(function (popoverTriggerEl) {
  return new bootstrap.Popover(popoverTriggerEl)
})

My importmap.rb

pin "application", preload: true
pin "@hotwired/turbo-rails", to: "turbo.min.js", preload: true
pin "@hotwired/stimulus", to: "stimulus.min.js", preload: true
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js", preload: true

pin "bootstrap", to: "https://ga.jspm.io/npm:bootstrap@5.1.3/dist/js/bootstrap.esm.js"#, preload: true
pin "@popperjs/core", to: "https://unpkg.com/@popperjs/core@2.11.2/dist/esm/index.js"#, preload: true # use unpkg.com as ga.jspm.io contains a broken popper package

pin "chartkick", to: "chartkick.js", preload: true
pin "Chart.bundle", to: "Chart.bundle.js", preload: true

pin_all_from "app/javascript/controllers", under: "controllers"

pin "trix"
pin "@rails/actiontext", to: "actiontext.js"

My gems:

ruby "3.2.0"

# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem "rails", "~> 7.1.3", ">= 7.1.3.2"

# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]
gem "sprockets-rails"

# Use postgresql as the database for Active Record
gem "pg", "~> 1.2"

#web server unicorn
gem 'unicorn', '~> 6.1'

# Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails]
gem "importmap-rails"

# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]
gem "turbo-rails"

# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]
gem "stimulus-rails"

# Build JSON APIs with ease [https://github.com/rails/jbuilder]
gem "jbuilder"

# Use Redis adapter to run Action Cable in production
gem "redis", ">= 4.0.1"

# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
# gem "kredis"

# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
# gem "bcrypt", "~> 3.1.7"

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "tzinfo-data", platforms: %i[ windows jruby ]

# Reduces boot times through caching; required in config/boot.rb
gem "bootsnap", require: false

# Bootstrap 5
gem "bootstrap"
# Use Sass to process CSS
gem "sassc-rails"
gem 'devise'
gem 'devise-i18n'

gem 'pagy'

gem "chartkick"
gem "groupdate"

gem "font-awesome-sass", "~> 6.2.1"

gem 'tinymce-rails'
gem 'tinymce-rails-langs'

gem 'faker'

gem 'execjs'
gem 'therubyracer'

gem "dockerfile-rails", ">= 1.6", :group => :development

Any idea what could be wrong?

I appreciate any help

This looks to be an application that was created well before Rails 7.1, and upgraded.

Check to see if config/environments/production.rb has a line like the following

config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present?

If so, the fix would be to add the following to the ENV line with the comment # Set production environment:

RAILS_LOG_TO_STDOUT="1" \

If that config line isn’t present, try it.

Adding the following to fly.toml would also work:

[[statics]]
  guest_path = "/rails/public"
  url_prefix = "/"

Finally – and this is not related – I note in your logs Booting WEBrick. This is not recommended for production. Consider upgrading to puma:

bundle add puma

Thanks for the answer, I finally made a clean implementation of rails 7.1 and added what you pointed out to the fly.toml file. Now everything works fine. Thank you so much!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.