Shrine

Shrine

  • Guides
  • Plugins
  • External
  • Discourse
  • GitHub
  • Wiki

›Validation

Attachment

  • Active Record
  • Column
  • Entity
  • Model
  • Sequel

Flow

  • Backgrounding
  • Presign Endpoint
  • Upload Endpoint

Processing

  • Derivation Endpoint
  • Derivatives

Source

  • Data URI
  • Rack File
  • Remote URL

Validation

  • Remove Invalid
  • Validation
  • Validation Helpers

Metadata

  • Add Metadata
  • Determine MIME Type
  • Infer Extension
  • Metadata Attributes
  • Refresh Metadata
  • Restore Cached Data
  • Signature
  • Store Dimensions
  • Type Predicates

Downloading

  • Download Endpoint
  • Rack Response
  • Tempfile

Form

  • Cached Attachment Data
  • Form Assign
  • Remove Attachment

Settings

  • Default Storage
  • Default URL
  • Dynamic Storage
  • Multi Cache
  • Pretty Location
  • Upload Options
  • URL Options

Other

  • Atomic Helpers
  • Included
  • Instrumentation
  • Keep Files
  • Mirroring
Edit

Remove Invalid

The remove_invalid plugin automatically deletes and deassigns a new assigned file if it was invalid. If there was a previous file attached, it will be assigned back.

plugin :remove_invalid
# without previous file 
photo.image        #=> nil 
photo.image = file # validation fails, assignment is reverted 
photo.valid?       #=> false 
photo.image        #=> nil 
 
# with previous file 
photo.image        #=> #<Shrine::UploadedFile id="foo" ...> 
photo.image = file # validation fails, assignment is reverted 
photo.valid?       #=> false 
photo.image        #=> #<Shrine::UploadedFile id="foo" ...> 
← Remote URLValidation →
Shrine
Docs
GuidesPluginsExternalContributing
Community
DiscourseStack Overflow
More
BlogGitHubStar
Follow @shrine_rb
Copyright © 2022 Janko Marohnić