class method self.blob

Ruby on Rails 7.2.3

Since v7.0.10

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

Signature

self.blob(filename:, **attributes)

Generate a YAML-encoded representation of an ActiveStorage::Blob instance’s attributes, resolve the file relative to the directory mentioned by ActiveSupport::Testing::FileFixtures.file_fixture, and upload the file to the Service

Examples

# tests/fixtures/active_storage/blobs.yml
second_thumbnail_blob: <%= ActiveStorage::FixtureSet.blob(
  filename: "second.svg",
) %>

third_thumbnail_blob: <%= ActiveStorage::FixtureSet.blob(
  filename: "third.svg",
  content_type: "image/svg+xml",
  service_name: "public"
) %>

Parameters

filename keyreq
attributes keyrest
Source
# File activestorage/lib/active_storage/fixture_set.rb, line 66
    def self.blob(filename:, **attributes)
      new.prepare Blob.new(filename: filename, key: generate_unique_secure_token), **attributes
    end

Defined in activestorage/lib/active_storage/fixture_set.rb line 66 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveStorage::FixtureSet

Type at least 2 characters to search.

↑↓ navigate · open · esc close