Module: ActiveScaffold::Bridges::FileColumn::FileColumnBridge

Defined in:
lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#file_column_fieldsObject

Returns the value of attribute file_column_fields.



7
8
9
# File 'lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb', line 7

def file_column_fields
  @file_column_fields
end

Instance Method Details

#configure_file_column_field(field) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb', line 25

def configure_file_column_field(field)
  # set list_ui first because it gets its default value from form_ui
  columns[field].list_ui ||= model.field_has_image_version?(field, 'thumb') ? :thumbnail : :download_link_with_filename
  columns[field].form_ui ||= :file_column

  # these 2 parameters are necessary helper attributes for the file column that must be allowed to be set to the model by active scaffold.
  columns[field].params.add "#{field}_temp", "delete_#{field}"

  # set null to false so active_scaffold wont set it to null
  # delete_file_column will take care of deleting a file or not.
  _columns_hash[field.to_s].instance_variable_set('@null', false)
rescue StandardError
  false
end

#initialize(model_id) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb', line 8

def initialize(model_id)
  super

  return unless ActiveScaffold::Bridges::FileColumn::FileColumnHelpers.klass_has_file_column_fields?(model)

  model.send :extend, ActiveScaffold::Bridges::FileColumn::FileColumnHelpers

  # include the "delete" helpers for use with active scaffold, unless they are already included
  model.generate_delete_helpers

  # switch on multipart
  update.multipart = true
  create.multipart = true

  model.file_column_fields.each { |field| configure_file_column_field(field) }
end