Rails:虽然由球童正确使用,但在生产模式中无法找到资产

我几乎几天都试图解决这个问题。

我试图在生产模式下在rails网站上运行我的ruby,但是(某些)资产无法提供。 图像位于自定义子文件夹(app / assets / audio / testfolder / demo.png)中,该子文件夹已添加到Rails.application.config.assets.paths并正确预编译但我总是收到错误

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

或者更具体:

 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:  [dd7b2824-614f-4e55-ba32-83548f79b2e1] 12:  [dd7b2824-614f-4e55-ba32-83548f79b2e1] 13:  [dd7b2824-614f-4e55-ba32-83548f79b2e1] 14: <audio src="" type="audio/mpeg" controls preload="none"> [dd7b2824-614f-4e55-ba32-83548f79b2e1] 15:  [dd7b2824-614f-4e55-ba32-83548f79b2e1] 16:  

图像可以直接访问localhost:81 / assets / demo-57cec01fc3b0b102085dc4de14576f8fd86f8298aed121ce17245df0546276d4.png,因此webserver(caddy)似乎不是问题所在。

我在github( https://github.com/Kafkalasch/RailsAssetsErrorDemo )上托管了一个简单的演示项目,以便轻松地重现问题。

只需克隆项目,预编译资产rails assets:precompile ,使用给定的Caddy文件, caddy -conf Caddyfile启动caddy服务器并使用config / puma.production.rb puma -C RubyDemo/config/puma.production.rb启动puma

我使用的是:ruby 2.4.1 puma 3.10.0 rails 5.1.4球童0.10.6

我可以在Debian和Mac OS X上重现这个问题,所以我不认为操作系统是相关的。

我想使用我的网络服务器来提供静态文件,所以我正在寻找另一种解决方案,而不仅仅是设置config.assets.compile = true

有没有人有想法或任何提示我如何解决我的问题?

我很感激任何回应。

我在生产和开发中用puma webserver测试了你的应用程序。

我通过在index.html.erb文件中包含mp3png文件的文件夹来解决错误。

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

因为您的图像和资产是在public/assets/testfolder而不是public/assets中预编译的

问题已经解决了