Module: Paperclip::Schema::Statements

Defined in:
lib/paperclip/schema.rb

Instance Method Summary collapse

Instance Method Details

#add_attachment(table_name, *attachment_names) ⇒ Object

Raises:

  • (ArgumentError)


22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/paperclip/schema.rb', line 22

def add_attachment(table_name, *attachment_names)
  raise ArgumentError, "Please specify attachment name in your add_attachment call in your migration." if attachment_names.empty?

  options = attachment_names.extract_options!

  attachment_names.each do |attachment_name|
    COLUMNS.each_pair do |column_name, column_type|
      column_options = options.merge(options[column_name.to_sym] || {})
      add_column(table_name, "#{attachment_name}_#{column_name}", column_type, column_options)
    end
  end
end

#drop_attached_file(*args) ⇒ Object



48
49
50
51
# File 'lib/paperclip/schema.rb', line 48

def drop_attached_file(*args)
  ActiveSupport::Deprecation.warn "Method `drop_attached_file` in the migration has been deprecated and will be replaced by `remove_attachment`."
  remove_attachment(*args)
end

#remove_attachment(table_name, *attachment_names) ⇒ Object

Raises:

  • (ArgumentError)


35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/paperclip/schema.rb', line 35

def remove_attachment(table_name, *attachment_names)
  raise ArgumentError, "Please specify attachment name in your remove_attachment call in your migration." if attachment_names.empty?

  options = attachment_names.extract_options!

  attachment_names.each do |attachment_name|
    COLUMNS.each_pair do |column_name, column_type|
      column_options = options.merge(options[column_name.to_sym] || {})
      remove_column(table_name, "#{attachment_name}_#{column_name}", column_type, column_options)
    end
  end
end