Rails 6 not serving static files

Viewed 1202

I've just upgraded a rails 5.1 project to Rails 6 and finally got it to render views. However, I still can't get Puma (4.3.3) to serve static files from the public/ folder. I opted for using Sprockets 4.0 instead of Webpack due to the difficulty of setting it up. I get this error:

Sprockets::Rails::Helper::AssetNotFound - The asset "intro_video.mp4" is not present in the asset pipeline.:
  app/views/home/_intro_video.html.haml:1
  app/views/home/index.html.haml:52

Started POST "/__better_errors/82e7c6297114c48a/variables" for 127.0.0.1 at 2020-04-02 09:05:05 -0400

I'm in the development environment and have added config.serve_static_assets = true to my config/environments/development.rb and rebooted the server. The page in question is linking to 'intro_video.mp4' which is in the root of the public/ folder. If I put localhost:3000/intro_video.mp4 directly into Firefox I get a ActionController::RoutingError: No route matches [GET] \"/intro_video.mp4\" error.

Any help is appreciated. Thank you.

EDIT: I've tried moving the intro_video.mp4 file to my app/assets/images directory but now I get this strange issue:

SassC::SyntaxError at /

Error: Undefined variable: "$light-gray". on line 15:10 of app/assets/stylesheets/datepicker.scss color: $light-gray;

Which means that the @import 'variables' line in my application.scss does not work, but all the other files referenced there work. In fact, if I add any files to my app/assets/images directory this happens. This makes no sense to me...

EDIT (again): So I fixed the CSS issue by removing this from app/assets/config/manifest.js

//= link_directory ../stylesheets .css

...which was affecting the load order of my stylesheets Still can't get anything to work from the public/ directory, so I'll just settle by moving everything to app/assets/images.

1 Answers

For Rails 6, the following should work:

# config/environments/production.rb
config.public_file_server.enabled = true
Related