Rails: Assets cannot be found in production mode, although they are properly served by caddy

I am trying to fix this problem almost the other day.

I am trying to run my ruby ​​on rails website in production mode, but (some of them) it is not possible to service the assets. Images are located in a user subfolder (app / assets / audio / testfolder / demo.png), which is added to Rails.application.config.assets.paths and precompiled correctly, but I always get an error

 ActionView::Template::Error (The asset "demo.png" is not present in the asset pipeline.) 

or more specifically:

 I, [2017-09-25T00:38:32.859541 #41037] INFO -- : [dd7b2824-614f-4e55-ba32-83548f79b2e1] Started GET "/" for 127.0.0.1 at 2017-09-25 00:38:32 +0200 I, [2017-09-25T00:38:32.860377 #41037] INFO -- : [dd7b2824-614f-4e55-ba32-83548f79b2e1] Processing by TestControllerController#index as HTML I, [2017-09-25T00:38:32.861240 #41037] INFO -- : [dd7b2824-614f-4e55-ba32-83548f79b2e1] Rendering test_controller/index.html.erb within layouts/application I, [2017-09-25T00:38:32.861558 #41037] INFO -- : [dd7b2824-614f-4e55-ba32-83548f79b2e1] Rendered test_controller/index.html.erb within layouts/application (0.1ms) I, [2017-09-25T00:38:32.863790 #41037] INFO -- : [dd7b2824-614f-4e55-ba32-83548f79b2e1] Completed 500 Internal Server Error in 3ms F, [2017-09-25T00:38:32.864505 #41037] FATAL -- : [dd7b2824-614f-4e55-ba32-83548f79b2e1] F, [2017-09-25T00:38:32.864789 #41037] FATAL -- : [dd7b2824-614f-4e55-ba32-83548f79b2e1] ActionView::Template::Error (The asset "demo.png" is not present in the asset pipeline.): F, [2017-09-25T00:38:32.865058 #41037] FATAL -- : [dd7b2824-614f-4e55-ba32-83548f79b2e1] 10: [dd7b2824-614f-4e55-ba32-83548f79b2e1] 11: <body> [dd7b2824-614f-4e55-ba32-83548f79b2e1] 12: <%= yield %> [dd7b2824-614f-4e55-ba32-83548f79b2e1] 13: <%= image_tag(yield(:img)) %> [dd7b2824-614f-4e55-ba32-83548f79b2e1] 14: <audio src="<%= audio_path(yield(:audio))%>" type="audio/mpeg" controls preload="none"></audio> [dd7b2824-614f-4e55-ba32-83548f79b2e1] 15: </body> [dd7b2824-614f-4e55-ba32-83548f79b2e1] 16: </html> 

The image can be accessed using localhost: 81 / assets / demo-57cec01fc3b0b102085dc4de14576f8fd86f8298aed121ce17245df0546276d4.png, so the web server (caddy) does not seem to be a problem.

I had a simple demo project on github ( https://github.com/Kafkalasch/RailsAssetsErrorDemo ) to easily reproduce the problem.

Just clone the project, pre-combine the rails assets:precompile , start the caddy server with the given Caddyfile, caddy -conf Caddyfile and start puma with config / puma.production.rb puma -C RubyDemo/config/puma.production.rb

I use: ruby ​​2.4.1 puma 3.10.0 rails 5.1.4 caddy 0.10.6

I could reproduce this problem on Debian and Mac OS X, so I do not assume that the OS matters.

I want to use my web server for working with static files, so I'm looking for a different solution than just setting config.assets.compile = true

Does anyone have an idea or any hint on how I can solve my problem?

I am grateful for any answer.

0
source share
1 answer

I tested your application with the puma web server during production and development.

I solved the error by including the folder for mp3 and png files in your index.html.erb file.

 <% provide(:img, "testfolder/demo.png") %> <% provide(:audio, "testfolder/demo.mp3") %> 

because your images and assets are precompiled inside public/assets/testfolder instead of public/assets

Problem resolved

0
source

Source: https://habr.com/ru/post/1271628/


All Articles