Class: UploaderInput

Inherits:
SimpleForm::Inputs::FileInput
  • Object
show all
Includes:
Assetable::Uploaders
Defined in:
app/inputs/uploader_input.rb

Instance Method Summary collapse

Methods included from Assetable::Uploaders

#asset_preview, #directions_html, #gallery_preview

Instance Method Details

#inputObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/inputs/uploader_input.rb', line 5

def input
  # Create the hidden input as fields_for
  fieldname = "#{object_name}[#{attribute_name}_association_attributes][asset_id]"

  # For has_one uploaders, we'll add a nil valued hidden field so that we can
  # remove an image (similar to how checkboxes work)
  hidden_field = template.hidden_field_tag(fieldname, nil, class: "assetable-uploader-input")
  
  # Asset preview
  preview = asset_preview(object.send("#{attribute_name}"), :asset, fieldname)

  # Uploader HTML = preview + hidden input
  uploader_html = template.(:div, (hidden_field + preview.html_safe), class: "uploader-assets-wrapper")

  # Create and return the uploader html
  uploader_wrapper = template. :div, (uploader_html + directions_html.html_safe), class: "assetable-uploader"
  return uploader_wrapper
end