跳至内容 跳至搜索

Active Storage 变体记录

类似于 ActiveStorage::Variant,但在数据库中将变体信息存储为 ActiveStorage::VariantRecord。这仅在启用 ActiveStorage.track_variants 时使用。

方法
D
F
I
N
P

属性

[R] blob
[R] variation

类公共方法

new(blob, variation)

# File activestorage/app/models/active_storage/variant_with_record.rb, line 14
def initialize(blob, variation)
  @blob, @variation = blob, ActiveStorage::Variation.wrap(variation)
end

实例公共方法

destroy()

销毁记录并从服务中删除文件。

# File activestorage/app/models/active_storage/variant_with_record.rb, line 32
def destroy
  record&.destroy
end

filename()

# File activestorage/app/models/active_storage/variant_with_record.rb, line 27
def filename
  ActiveStorage::Filename.new "#{blob.filename.base}.#{variation.format.downcase}"
end

image()

# File activestorage/app/models/active_storage/variant_with_record.rb, line 23
def image
  record&.image
end

processed()

# File activestorage/app/models/active_storage/variant_with_record.rb, line 18
def processed
  process unless processed?
  self
end