Rails Video上传纸袋纸条 - av-transcoder表单保存



非常感谢您的任何帮助。我已经尝试了几天,但我无法弄清楚。我正在尝试构建视频上传表格。令我惊讶的是,我找不到有关该主题的太多信息。

我正在将纸袋与Paperclip-av-transcoder一起使用。它似乎让我创建一个Video.new记录,但我无法获得保存@user.videos.build(video_params)的记录。我知道参数正在传递,因为它们在以前的错误消息中显示。我没有错误,只是" nope。不起作用"字符串。

class VideosController < ApplicationController
  def new
    @user = User.find(current_user)
    @video = @user.build_video
  end
  def create
    @user = User.find(current_user)
    @video = @user.videos.build(video_params)
    if @video.save
       redirect_to admin_ad_pg_path, :flash => { :error => "It worked!" }
    else
       redirect_to admin_ad_pg_path, :flash => { :error => "Nope. Didn't work." }
    end
  end
  private
    def video_params
      params.require(:video).permit(:avatar)
    end
end

Video Model:
class Video < ApplicationRecord
    belongs_to :user
    has_attached_file :avatar, :styles => {
    :medium => { :geometry => "640x480", :format => 'flv' },
    :thumb => { :geometry => "100x100#", :format => 'jpg', :time => 10 }
    }, :processors => [:transcoder]
    validates_attachment :avatar, content_type: { content_type: /flv/.*Z/ }
end
User Model
class User < ApplicationRecord
has_many :videos
end

 Video Form:
<%= flash[:error] %>
      <%= form_for @video, url: user_videos_path(current_user), :html => { multipart: true } do |f| %>
        <div class="form-group">
          <%= f.label :avatar %>
          <%= f.file_field :avatar, class: 'form-control' %>
        </div>
      <%= f.submit 'Submit',class: 'btn btn-default' %>
      <% end %>
Paperclip Migration:
class AddAttachmentAvatarToVideos < ActiveRecord::Migration
  def self.up
    change_table :videos do |t|
      t.attachment :avatar
    end
  end
  def self.down
    remove_attachment :videos, :avatar
  end
end

谢谢马特

嘿,如果不这样做,请进行此迁移,然后重试。

def change
  add_column :users, :avatar_meta, :data_type
end

您可以使用:JSON,:JSONB,:HSTORE的数据类型,甚至仅:String

最新更新