Shrine

Shrine

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

›Form

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 Attachment

The remove_attachment plugin allows you to delete attachments through checkboxes on the web form.

plugin :remove_attachment

The plugin adds the #remove_<name> accessor to your model, which removes the attached file if it receives a truthy value:

photo.image #=> #<Shrine::UploadedFile> 
photo.remove_image = 'true'
photo.image #=> nil 

This allows you to add a checkbox form field for removing attachments:

form_for photo do |f|
  # ... 
  f.check_box :remove_image
end

If you're using the Shrine::Attacher directly, you can use the Attacher#remove accessor:

attacher.file #=> #<Shrine::UploadedFile> 
attacher.remove = '1'
attacher.file #=> nil 
← Form AssignDefault Storage →
Shrine
Docs
GuidesPluginsExternalContributing
Community
DiscourseStack Overflow
More
BlogGitHubStar
Follow @shrine_rb
Copyright © 2022 Janko Marohnić