开发者

Rails 3.1 asset pipeline needs restart if new file created?

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开发者_JS百科 -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>


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜