Routing Error for static files (`/documents/cv.pdf`) in development
Issue: Linking to PDFs I placed in public/documents/
resulted in No route matches [GET] /documents/cv.pdf
in the development environment.
Cause: By default, the Rails development environment often doesn't serve static files from the public
directory. This is typically enabled only in production for performance reasons.
Resolution:
1. I enabled static file serving in development by setting config.public_file_server.enabled = true
in config/environments/development.rb
.
2. I ensured the PDF files were correctly placed in til_tracker/public/documents/
.
3. I restarted the Rails server (./bin/dev
).
Learning: To serve static assets (like PDFs, images) directly from the public
folder in the development environment, I learned I must explicitly set config.public_file_server.enabled = true
in config/environments/development.rb
and restart the server. In production, this is usually handled by the webserver (like Nginx or Apache) or enabled by default in production.rb
.
Learned on: April 22, 2024
Edit