URI不匹配Rails在生产环境中的资产URL中生成MD5摘要,但控制器GET是非MD5 URL [英] URI mismatch Rails generates MD5 digest in asset URL in production, but controller GET's a non-MD5 URL

查看:134
本文介绍了URI不匹配Rails在生产环境中的资产URL中生成MD5摘要,但控制器GET是非MD5 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用html5视频标记的Rails应用程序,以及相应的Rails video_tag()方法在页面上显示视频。



我已经添加了

 <%= video_tagcar_circle.mp4,width:640,height:500 ,控件:true%> 

添加到视图中的html.erb文件中。



Rails 3.2在/ public目录中查找视频,因此我将视频添加到名为 public / videos 的文件夹中。 为了将此文件夹添加到资产管道,我将此行添加到 application.rb

中。

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

这部分工作。视频资源会进行预编译,而其中包含视频的页面确实会加载。但是,这些视频本身没有。这是因为,尽管视频可以在各自的URL上进行查看,例如 /videos/car_circle.mp4 ,但视频应该在网页上的视频的URI load is /videos/car_circle-4e5f6739c10827a6fc3d479d1ac5c275.mp4



这是Rails添加到生产中URI的MD5摘要。我需要我的视频URI来匹配视频所在页面上的摘要URI。



到目前为止,我试图通过设置

$来禁用摘要b
$ b

  config.assets.digest = true 

为false。然而这并不推荐,它会让我的应用程序崩溃。



关于如何正确获取我的资产GET'ed的任何建议?显然,这只是生产中的一个问题,这是默认情况下Rails使用摘要URI的唯一地方。非常感谢。

解决方案

尝试使用纯html元素声明如下:

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

即使 .erb 文件仍然会接受纯文本html声明应该没有任何Rails的变更。


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.

解决方案

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.

这篇关于URI不匹配Rails在生产环境中的资产URL中生成MD5摘要,但控制器GET是非MD5 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆