Class: FileuploadInput

Inherits:
SimpleForm::Inputs::StringInput
  • Object
show all
Defined in:
app/inputs/fileupload_input.rb

Overview

Custom simple_form input type for integration with bootstrap-fileupload.js

http://jasny.github.io/bootstrap/javascript.html#fileupload

Instance Method Summary collapse

Instance Method Details

#c_tag(*args) ⇒ Object



30
31
32
# File 'app/inputs/fileupload_input.rb', line 30

def c_tag(*args)
  template.(*args)
end

#input(_wrapper_options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/inputs/fileupload_input.rb', line 9

def input(_wrapper_options = {})
  if object.send("#{attribute_name}?")
    preview = object.send(attribute_name).file.filename
    css = 'exists'
  else
    preview = ''
    css = 'new'
  end
  input = c_tag(:div,
                c_tag(:span, preview, class: 'fileupload-preview'),
                class: 'uneditable-input input-small')
  button = c_tag(:span,
                 c_tag(:span, I18n.t(:fileupload_change), class: 'fileupload-exists') +
                   c_tag(:span, I18n.t(:fileupload_select), class: 'fileupload-new') +
                   @builder.file_field(attribute_name) + @builder.hidden_field("#{attribute_name}_cache"),
                 class: 'btn btn-file')
  c_tag(:div,
        c_tag(:div, input + button, class: 'input-append'),
        class: "fileupload fileupload-#{css}", data: { provides: 'fileupload' })
end