【问题标题】:carrierwave: update active record column within uploadercarrierwave:更新上传器中的活动记录列
【发布时间】:2014-03-20 12:29:35
【问题描述】:

我正在使用 Carrierwave 将视频文件上传到我的 Rails 应用程序。我的视频模型有一个属性“旋转”,我用它来存储视频的方向(例如,90、180、270 等)。

我想在我的上传器中设置“旋转”的值,我在其中确定视频是否旋转:

require 'mini_exiftool'

class VideoPathUploader < CarrierWave::Uploader::Base

process :encode

def encode
    video = MiniExiftool.new(@file.path)
    orientation = video.rotation

    # save the orientation of the video record here ??
    if orientation == 90
      # rotate video
      Rails.logger.debug "portrait video"
      aspect_ratio = video.imageheight.to_f / video.imagewidth.to_f
      encode_video(:mp4, custom: "-vf transpose=1", aspect: aspect_ratio)
    else
      aspect_ratio = video.imagewidth.to_f / video.imageheight.to_f
      encode_video(:mp4, resolution: :same, aspect: aspect_ratio)
    end
    instance_variable_set(:@content_type, "video/mp4")
    :set_content_type_mp4
  end

如何在我的上传器中引用模型并更新其属性之一?

【问题讨论】:

    标签: ruby-on-rails carrierwave uploader


    【解决方案1】:

    要在我的上传器中引用视频记录,我只需要调用 modelL:

    方向 = video.rotation model.rotation = 方向

    【讨论】:

      猜你喜欢
      • 2011-09-29
      • 1970-01-01
      • 2010-12-13
      • 2013-07-30
      • 1970-01-01
      • 2013-09-23
      • 2013-01-18
      • 1970-01-01
      相关资源
      最近更新 更多