没有使用Paperclip Gem上传的视频 - 在Rails中使用ffmpeg

时间:2014-08-06 14:38:58

标签: ruby video ruby-on-rails-4 migration paperclip

我可以上传我的图片但是,当我尝试上传视频时,它会以黑屏的形式发布,但播放按钮不起作用。我不知道哪里出错了。我需要一个视频播放器才能使用吗?

这可能是一个简单的解决方案,但我是Rails的新手。任何帮助是极大的赞赏。谢谢。

发布模型

        class Post < ActiveRecord::Base

    belongs_to :user

    has_attached_file :image, :styles => { :medium => "300x300>", :thumb => "100x100>" }
    has_attached_file :video, :styles => {:medium => { :geometry => "300x300", :format => 'flv'},:thumb => {:geometry => "100x100#", :format => 'jpg', :time => 15}
    }, :processors => [:ffmpeg] 



    validates_attachment_content_type :image, :content_type => ["image/jpg", "image/jpeg", "image/png", "image/gif"]
    validates_attachment_content_type :video, :content_type => ["video/mp4", "video.mov", "video/mpeg","video/mpeg4", "image/jpg", "image/jpeg"]

    validates :description, presence: true
    validates :image, presence: false
    validates :video, presence: false

end

AddAttachmentImageToPosts Model

    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

发布_form

  <div class="field">
    <%= f.label :image %>
    <%= f.file_field :image %>
  </div>


  <div class="field">
    <%= f.label :video %>
    <%= f.file_field :video %>
  </div></br>


  <div class="field">
    <%= f.label :description %>
    <%= f.text_field :description %>
  </div>

帖子显示

<div class="row">
    <div class="col-md-offset-4 col-med-8">
        <div class="panel panel-default">
        <div class="panel-heading center">
            <%= image_tag @post.image.url(:medium) %>
            <%= video_tag @post.video.url(:medium), controls: true, type: "video/mp4" %>
        </div>
        <div class="panel-body">
        <p><%= @post.description %></p>
        <p><strong><%= @post.user.name if @post.user %></strong></p>

    <% if @post.user == current_user %>
        <%= link_to edit_post_path(@post) do %>
        <span class="glyphicon glyphicon-edit"></span>
        Edit
      <% end %>
    <% end %>
    <%= link_to 'Back', posts_path %>
    </div>
</div>

0 个答案:

没有答案