URI mismatch Rails generates MD5 digest in asset URL in production, but controller GET's a non-MD5 URL

蹲街弑〆低调 提交于 2020-01-06 19:37:18

问题


I have a Rails app with a page or two that uses the html5 video tag, and the corresponding Rails video_tag() method to display video on the page.

I've added

<%= video_tag "car_circle.mp4", width: "640", height: "500", controls: true %>

to an html.erb file in views.

Rails 3.2 looks for videos in the /public directory, and so I've added my videos to a folder called public/videos.

In order to add this folder to the asset pipeline, I added this line to application.rb

  config.assets.paths << "#{Rails.root}/public/videos"

This partially works. The video assets do precompile, and the pages with the videos in them do in fact load. However, the videos themselves do not. This is due to the fact that, while the videos can be viewed at their respective URLs, for example /videos/car_circle.mp4, the URI of the video on the page where the videos should load is /videos/car_circle-4e5f6739c10827a6fc3d479d1ac5c275.mp4.

This is the MD5 digest Rails adds on to URI's in production. I need my video URI to match the digest'ed URI on the page where the video resides.

So far I have tried to disable digesting by setting

 config.assets.digest = true

to false. However this is not recommended and it makes my app crash anyhow.

Any suggestions on how to get my asset GET'ed correctly? Obviously this is only a problem in production, which is the only place where Rails uses digest'ed URI's by default. Much appreciated.


回答1:


Try to use plain html element declaration as follows:

<video width="640" height="500" control="controls">
    <source src="../../../public/videos/car_circle.mp4" type="video/mp4">
</video>

Even .erb file will still accept plain html declaration that should be free from any Rails' alteration.




回答2:


Using plain html for the video tag also worked for me.

I kept the video files in public/videos

and referenced the html as

<video autoplay="autoplay" loop="loop" src="/videos/test.mp4">

This worked fine for me.



来源:https://stackoverflow.com/questions/12674399/uri-mismatch-rails-generates-md5-digest-in-asset-url-in-production-but-controll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!