Rails 4 - video_tag的路由错误

时间:2016-04-19 07:21:27

标签: ruby-on-rails ruby video paperclip

在rails 4.2.4中,我使用paperclip gem来上传视频文件。上传视频文件后,我在显示时遇到一个路径错误。

No route matches [GET] "/videos/User_1/3/sample.webm"

实际文件路径为/home/shruthi/Projects/Test/videos/User_1/3/sample.webm

以下行添加到config / application.rb

config.assets.enabled = true
config.assets.paths << "#{Rails.root}/videos"

在模特中,

has_attached_file :document,
:path => "#{Rails.root}/videos/:user_id/:event_id/:basename.:extension",
:url => "/videos/:user_id/:event_id/:basename.:extension",
:storage => :filesystem

validates_attachment_presence :document
validates_attachment :document,
:content_type=>{:content_type=>/^(video\/(mp4|avi|mpeg|ogg|quicktime|webm|x-matroska|x-ms-wmv|x-flv|3gpp))/},
:size => { :less_than =>5.megabytes }
validates :event, :presence=>true

在观看中,

<%= video_tag video.document.url, type: video.document_content_type %>

请告诉我如何显示视频文件?

0 个答案:

没有答案