#Rails assets won't load when using nixpacks

6 messages · Page 1 of 1 (latest)

drifting panther
#

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.

#

The img tag can't find the image for example. The same happens for CSS and JS files

drifting panther
#
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

drifting panther
#
  # 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