Rails assets won't load when using nixpacks

Well, for some reason the assets in the public folder in Rails just won't load. They are there, I can see them when I run railway run ls public. But they throw a 404 error.
3 Replies
Stibnite
Stibnite2y ago
The img tag can't find the image for example. The same happens for CSS and JS files
Stibnite
Stibnite2y ago
The build logs
Stibnite
Stibnite2y ago
config.serve_static_assets configures Rails itself to serve static assets. Defaults to true, but in the production environment is turned off as the server software (e.g. Nginx or Apache) used to run the application should serve static assets instead. Unlike the default setting set this to true when running (absolutely not recommended!) or testing your app in production mode using WEBrick. Otherwise you won´t be able use page caching and requests for files that exist regularly under the public directory will anyway hit your Rails app.
config.serve_static_assets configures Rails itself to serve static assets. Defaults to true, but in the production environment is turned off as the server software (e.g. Nginx or Apache) used to run the application should serve static assets instead. Unlike the default setting set this to true when running (absolutely not recommended!) or testing your app in production mode using WEBrick. Otherwise you won´t be able use page caching and requests for files that exist regularly under the public directory will anyway hit your Rails app.
from https://guides.rubyonrails.org/v3.2/configuring.html Let's see if it's caused by this config
# Disable serving static files from the `/public` folder by default since
# Apache or NGINX already handles this.
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
# Disable serving static files from the `/public` folder by default since
# Apache or NGINX already handles this.
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
Fixed it by adding RAILS_SERVE_STATIC_FILES environment variable