instance method variant

Ruby on Rails 7.0.10

Since v7.0.10

Available in: v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

variant(transformations)

Returns an ActiveStorage::Variant or ActiveStorage::VariantWithRecord instance for the attachment with the set of transformations provided. See ActiveStorage::Blob::Representable#variant for more information.

Raises an ArgumentError if transformations is a Symbol which is an unknown pre-defined variant of the attachment.

Parameters

transformations req
Source
# File activestorage/app/models/active_storage/attachment.rb, line 56
  def variant(transformations)
    case transformations
    when Symbol
      variant_name = transformations
      transformations = variants.fetch(variant_name) do
        record_model_name = record.to_model.model_name.name
        raise ArgumentError, "Cannot find variant :#{variant_name} for #{record_model_name}##{name}"
      end
    end

    blob.variant(transformations)
  end

Defined in activestorage/app/models/active_storage/attachment.rb line 56 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveStorage::Attachment

Type at least 2 characters to search.

↑↓ navigate · open · esc close