Я использую Carrierwave для загрузки видеофайлов в мое приложение Rails. Моя модель видео имеет атрибут «вращение», который я использую для хранения ориентации видео (например, 90, 180, 270 и т. Д.).carrierwave: обновить активную колонку записей внутри пользователя
Я хочу, чтобы установить значение «вращения» в моем Uploader, где я определяющий повернут ли видео или нет:
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
Как ссылаться на модель и обновить один из его атрибуты в моем загрузчике?