Module: SimpleFormExtension::FileConcern
- Included in:
- Inputs::FileInput, Inputs::ImageInput
- Defined in:
- lib/simple_form_extension/file_concern.rb
Instance Method Summary collapse
- #activestorage_attachment_attached? ⇒ Boolean
- #existing_file_name ⇒ Object
- #existing_file_tag ⇒ Object
- #file_exists? ⇒ Boolean
- #file_preview_and_remove_button ⇒ Object
- #file_url ⇒ Object
- #paperclip_attachment_attached? ⇒ Boolean
- #remove_attachment_method ⇒ Object
- #remove_file_button ⇒ Object
Instance Method Details
#activestorage_attachment_attached? ⇒ Boolean
66 67 68 69 70 |
# File 'lib/simple_form_extension/file_concern.rb', line 66 def ||= object.try(attribute_name).try(:attached?) && object.try(attribute_name).blob end |
#existing_file_name ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/simple_form_extension/file_concern.rb', line 28 def existing_file_name if object.send(:"#{ attribute_name }_file_name").html_safe elsif = object.send(attribute_name) .filename.to_s end end |
#existing_file_tag ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/simple_form_extension/file_concern.rb', line 3 def existing_file_tag return '' unless file_exists? content_tag(:div, class: 'input-group help-block existing-file', data: { provides: 'existing-file'}) do content_tag(:span, class: 'input-group-addon') do "#{ _translate('file.existing_file') } : ".html_safe end + end end |
#file_exists? ⇒ Boolean
50 51 52 |
# File 'lib/simple_form_extension/file_concern.rb', line 50 def file_exists? @file_exists ||= || end |
#file_preview_and_remove_button ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/simple_form_extension/file_concern.rb', line 15 def content_tag(:div, class: 'btn-group') do template.link_to(file_url, class: 'btn btn-default ', target: '_blank', data: { toggle: 'existing-file' }) do content_tag(:i, '', class: 'fa fa-file') + " ".html_safe + existing_file_name end + end end |
#file_url ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/simple_form_extension/file_concern.rb', line 54 def file_url if object.send(attribute_name) elsif template.polymorphic_url(object.send(attribute_name)) end end |
#paperclip_attachment_attached? ⇒ Boolean
62 63 64 |
# File 'lib/simple_form_extension/file_concern.rb', line 62 def ||= object.try(:"#{ attribute_name }?") end |
#remove_attachment_method ⇒ Object
46 47 48 |
# File 'lib/simple_form_extension/file_concern.rb', line 46 def [:remove_method] || :"remove_#{ attribute_name }" end |
#remove_file_button ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/simple_form_extension/file_concern.rb', line 37 def return unless object.respond_to?(:"#{ remove_attachment_method }=") content_tag(:button, class: 'btn btn-default', type: 'button', data: { dismiss: 'existing-file' }) do content_tag(:i, '', class: 'fa fa-remove', data: { :'removed-class' => 'fa fa-refresh' }) + @builder.hidden_field(, class: 'remove-file-input', value: nil) end end |