Skip to content

Active Storage attachment is nil #28

@cseelus

Description

@cseelus

Using File Validators file_content_type and file_size with Active Storage throw a Module::DelegationError error (content_type delegated to attachment, but attachment is nil and size delegated to attachment, but attachment is nil), when a form for a Model thats being validated gets submitted without attaching a file.

The following workaround works for now:

validates :image, file_content_type: { allow: ['image/jpeg', 'image/png', 'image/gif'] }, if: -> { image.attached? }

This might fit into the README, should I open a PR?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions