Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 回形针视频上传_Ruby On Rails_Ruby_File Upload_Paperclip_Ruby On Rails 4 - Fatal编程技术网

Ruby on rails 回形针视频上传

Ruby on rails 回形针视频上传,ruby-on-rails,ruby,file-upload,paperclip,ruby-on-rails-4,Ruby On Rails,Ruby,File Upload,Paperclip,Ruby On Rails 4,我正在尝试在我的帖子中启用视频上传。 无法使其显示视频。视频上传后,我可以确认,当我右键点击视频区域并下载时。问题是如何正确地看待它 迁移: class AddAttachmentVideoToPosts < ActiveRecord::Migration def self.up change_table :posts do |t| t.attachment :video end end def self.down drop_attache

我正在尝试在我的帖子中启用视频上传。 无法使其显示视频。视频上传后,我可以确认,当我右键点击视频区域并下载时。问题是如何正确地看待它

迁移:

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 AddAttachmentVideoToPosts
后期模型

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
class Post'created\u at desc'
属性可访问:内容,:标题,:照片,:照片删除,:视频,:视频删除,:依赖=>:销毁
已附加文件:photo,:styles=>{:thumb=>“600x600”、:Middle=>“300x300”、:small=>“160x160”}
是否已附加文件:视频
验证:标题的唯一性
验证是否存在:title、:content
有可销毁的文件:照片、视频
结束
我的帖子表单中的视频部分

<div class="visible-md visible-lg">
  <%= f.file_field :video, :style => "float: left;" %>
  <%= f.check_box :video_delete, :style => "float: left;" %> &nbsp;Delete video
  </div><br />
<div class="visible-xs">
  <%= f.file_field :video, :style => "center" %>
  <%= f.check_box :video_delete, :style => "center" %> &nbsp;Delete video
</div><br />

“浮动:左;”%>
“浮动:左;”%>删除视频

“中心”%> “中心”%>删除视频
后期放映中的视频部分

<% if @post.video? %>
<h1 class="center">
<%= @post.title %>
</h1><br />
<%= video_path @post.video.url %>       
<% end %>


我也尝试过使用不起作用的video_标签,当我尝试使用:

<iframe width="490" height="275" src="<%= video_path @post.video.url %>" frameborder="0" allowfullscreen autoplay="true">
            </iframe>

我有一个球员不会上场。
如果你仔细看看,也许能帮我想出一个可行的解决方案,我将不胜感激。谢谢

您应该使用
video
标记,而不是
iframe
(只有
video
标记具有自动播放选项)。请在此检查哪个浏览器支持哪些格式:

如果您想要交叉浏览器解决方案,请尝试VideoJS-
在这里您可以获得Rails插件-

回形针视频上传:

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
上周我也遇到了同样的问题-试试这个

Video model:
    has_attached_file :video, styles: {
        :medium => {
          :geometry => "640x480",
          :format => 'mp4'
        },
        :thumb => { :geometry => "160x120", :format => 'jpeg', :time => 10}
    }, :processors => [:transcoder]
    validates_attachment_content_type :video, content_type: /\Avideo\/.*\Z/
确保您已绑定:

gem 'paperclip', '~> 4.3.1'
gem 'aws-sdk', '< 2.0'
gem 'paperclip-av-transcoder'
gem "paperclip-ffmpeg", "~> 1.2.0"
确保在post_controller.rb中添加:

private

    def bscenes_params
        params.require(:post).permit(:video)
    end
上传表格:

<%= f.file_field :video %>
转到终端并键入:

brew options ffmpeg
然后运行以下命令以安装ffmpeg:

brew install ffmpeg --with-fdk-aac --with-ffplay --with-freetype --with-frei0r --with-libass --with-libvo-aacenc --with-libvorbis --with-libvpx --with-opencore-amr --with-openjpeg --with-opus --with-rtmpdump --with-schroedinger --with-speex --with-theora --with-tools

立即重新启动服务器并尝试上载视频!希望这有帮助-快乐编码:)

取决于您想要什么。请记住,托管您自己的用户上传的视频有一些问题。就像您确保获得跨浏览器兼容性的正确编码一样。是一个伟大的开源播放器,它将照顾您的视图层。如果您想要高跨浏览器兼容性,则需要为jplayer提供多个编码的路径。你可以使用像zen coder这样的服务。这确实非常昂贵,但他们都有一定程度的免费开发帐户来学习和试验他们的系统。谢谢,我要尝试一下jplayer:)@TyrelRichey我已经安装了jplayer,加载了皮肤,现在有了一个视频播放器外壳。但我现在不知道如何调用视频,以便播放器工作。我有这个jquery:$(document).ready(function(){$(“#jquery_jplayer_1”).jplayer({ready:function(){$(this).jplayer(“setMedia”,{m4v:,});},swfPath:“/assets/jplayer”,提供:“m4v”});获得要播放的示例视频,这意味着它将加载所有已安装的文件。虽然当我呼叫m4v时,它不会播放我的视频:“谢谢,是的,我使用了videojs。不过,这可不是什么好东西:P ffmpeg、回形针和flashplayer是让它在每个Webb浏览器中都能顺利运行的最佳解决方案!我使用Sidekiq转换背景中的视频。
brew options ffmpeg
brew install ffmpeg --with-fdk-aac --with-ffplay --with-freetype --with-frei0r --with-libass --with-libvo-aacenc --with-libvorbis --with-libvpx --with-opencore-amr --with-openjpeg --with-opus --with-rtmpdump --with-schroedinger --with-speex --with-theora --with-tools