ruby-on-rails – Paperclip视频上传
发布时间:2020-12-17 02:39:23 所属栏目:百科 来源:网络整理
导读:我正在尝试在我的帖子中启用视频上传功能. 无法让它显示视频.视频上传,我可以确认,虽然我设法右键点击视频区域并下载它.问题是如何正确查看它. 移民: class AddAttachmentVideoToPosts ActiveRecord::Migration def self.up change_table :posts do |t| t.a
我正在尝试在我的帖子中启用视频上传功能.
无法让它显示视频.视频上传,我可以确认,虽然我设法右键点击视频区域并下载它.问题是如何正确查看它. 移民: class AddAttachmentVideoToPosts < ActiveRecord::Migration def self.up change_table :posts do |t| t.attachment :video end end def self.down drop_attached_file :posts,:video end end def change create_table :videos do |t| t.string :video_file_name t.string :video_content_type t.integer :video_file_size t.datetime :video_updated_at t.timestamps end end 发布模型 class Post < ActiveRecord::Base default_scope :order => 'created_at desc' attr_accessible :content,:title,:photo,:photo_delete,:video,:video_delete,:dependent => :destroy has_attached_file :photo,:styles => { :thumb => "600x600#",:medium => "300x300#",:small => "160x160#"} has_attached_file :video validates_uniqueness_of :title validates_presence_of :title,:content has_destroyable_file :photo,:video end 视频部分在我的帖子_form中 <div class="visible-md visible-lg"> <%= f.file_field :video,:style => "float: left;" %> <%= f.check_box :video_delete,:style => "float: left;" %> Delete video </div><br /> <div class="visible-xs"> <%= f.file_field :video,:style => "center" %> <%= f.check_box :video_delete,:style => "center" %> Delete video </div><br /> Post Show中的视频部分 <% if @post.video? %> <h1 class="center"> <%= @post.title %> </h1><br /> <%= video_path @post.video.url %> <% end %> 我也尝试过使用video_tag但是当我尝试使用时: <iframe width="490" height="275" src="<%= video_path @post.video.url %>" frameborder="0" allowfullscreen autoplay="true"> </iframe> 我得到一个不会参加比赛的球员. 解决方法
您应该使用视频标记,而不是iframe(只有视频标记具有自动播放选项).在此处查看哪些浏览器支持哪些格式:
http://caniuse.com/#search=video
如果您需要crossbrowser解决方案,请尝试VideoJS – http://www.videojs.com/ (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |