Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.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 carrierwave多个文件上载和存储_Ruby On Rails_Ruby_Ruby On Rails 4_Carrierwave - Fatal编程技术网

Ruby on rails carrierwave多个文件上载和存储

Ruby on rails carrierwave多个文件上载和存储,ruby-on-rails,ruby,ruby-on-rails-4,carrierwave,Ruby On Rails,Ruby,Ruby On Rails 4,Carrierwave,我想用carrierwave进行多文件上传 当我上传一部电影时,我会将它转换成多种格式。mp4.mov 现在我想上传所有这些并将它们存储在DB中 如何使用carrierwave保存文件的版本 谢谢将相关属性添加到您的模型中,并引入“保存前”回调 class Video < ActiveRecord::Base mount_uploader :video, VideoUploader before_save :update_video_attributes private

我想用carrierwave进行多文件上传

当我上传一部电影时,我会将它转换成多种格式。mp4.mov

现在我想上传所有这些并将它们存储在DB中

如何使用carrierwave保存文件的版本


谢谢

将相关属性添加到您的模型中,并引入“保存前”回调

class Video < ActiveRecord::Base
  mount_uploader :video, VideoUploader

  before_save :update_video_attributes
  private

  def update_video_attributes
    if video.present? && video_changed?
      self.content_type = video.file.content_type
      self.file_size = video.file.size
    end
  end
end
class-Video

有关更多详细信息,请参见

我也可以在carrierwave uploader中执行此操作吗?是否必须在表中为每个元素设置一个特殊列?