如果创建新文件,Rails 3.1 资产管道需要重新启动吗?
我有一台服务器,它使用网络摄像头拍摄视频剪辑并将其放置在 #{Rails.root}/app/assets/videos
中。问题是在服务器重新启动之前我无法看到新创建的视频剪辑。有解决方法吗?
这是控制器中的代码:
@file_name = Time.now.strftime("%Y-%m-%d_%H-%M-%S-%p") + ".mp4"
system("ffmpeg -f video4linux2 -s 320x240 -t 10 -i /dev/video0
#{Rails.root.to_s}/app/assets/videos/#{@file_name}")
以及视图中的代码:
<video src="/assets/<%= @file_name %>" width="320" height="240">
Your browser does not support the video tag.
</video>
I have a server that's taking video clips with a webcam and placing them in #{Rails.root}/app/assets/videos
. The problem is I can't see newly created video clips until the server is restarted. Is there a workaround for this?
Here's the code in the controller:
@file_name = Time.now.strftime("%Y-%m-%d_%H-%M-%S-%p") + ".mp4"
system("ffmpeg -f video4linux2 -s 320x240 -t 10 -i /dev/video0
#{Rails.root.to_s}/app/assets/videos/#{@file_name}")
And in the view:
<video src="/assets/<%= @file_name %>" width="320" height="240">
Your browser does not support the video tag.
</video>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Rails 期望
public/
仅包含静态资源,这些静态资源在 Rails 服务器启动时就存在(或在 Rails 初始化期间构建并放置在那里),并且在部署新代码之前不会更改。如果您希望它与 Rails 配合良好,您将需要使用其他存储系统来存储视频文件。您将需要更新 Rails 应用程序以了解如何处理另一个存储系统。
Amazon S3 和 Rackspace Cloud Files 是不错的选择,但服务器上的知名目录也可能有效(只是不能是
public/
)。您可以使用 CarrierWave gem 来提供帮助。Rails expects that
public/
contains only static assets that are all there when the rails server starts (or are built and placed there during the rails initialization) and will not change until new code is deployed.You will need to use some other storage system to store your video files if you want it to work well with Rails. You will need to update your Rails application to know how to deal with another storage system.
Amazon S3 and Rackspace Cloud Files are decent choices, but a well-known directory on your server might work as well (it just can't be
public/
). You can use the CarrierWave gem to help.