Class: MediaInput

Inherits:
SimpleForm::Inputs::FileInput
  • Object
show all
Defined in:
app/inputs/media_input.rb

Instance Method Summary collapse

Instance Method Details

#input(wrapper_options) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/inputs/media_input.rb', line 2

def input(wrapper_options)
  # :preview_version is a custom attribute from :input_html hash, so you can pick custom sizes
  version = input_html_options.delete(:preview_version)
  out = '' # the output string we're going to build

  # append file input. it will work accordingly with your simple_form wrappers
  (out << @builder.file_field(attribute_name, input_html_options)).html_safe

  # check if there's an uploaded file (eg: edit mode or form not saved)
  if object.send("#{attribute_name}?")
    # append preview image to output
    out << template.image_tag(object.send(attribute_name).tap {|o| break o.send(version) if version}.send('url'))
  end
  return out
end