Module: Paperclip::Removable

Included in:
ClassMethods
Defined in:
lib/paperclip/removable.rb

Overview

Allows removal of previously uploaded files. Example:

In the model, you can specify:

class User < ActiveRecord::Base
  has_attached_file :photo, :removable => true
  attr_accessible   :photo, :remove_photo
end

In the form you can then have:

= f.inputs do
  = f.input :photo
  = f.input :remove_photo, :as => :boolean if f.object.photo?

Instance Method Summary collapse

Instance Method Details

#has_attached_file_with_removable(name, options = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/paperclip/removable.rb', line 23

def has_attached_file_with_removable(name, options = {})
  has_attached_file_without_removable(name, options)

  if attachment_definitions[name][:removable]
    define_method(:"remove_#{name}") do
      false
    end

    define_method(:"remove_#{name}=") do |value|
      value = ActiveRecord::ConnectionAdapters::Column.value_to_boolean(value)
      send(name).clear if value
      value
    end
  end
end