module SimpleFormExtension::FileConcern
Public Instance Methods
existing_file_name()
click to toggle source
# File lib/simple_form_extension/file_concern.rb, line 28 def existing_file_name if object.try(:"#{ attribute_name }?") object.send(:"#{ attribute_name }_file_name").html_safe elsif (attachment = object.try(attribute_name)).try(:attached?) attachment.filename.to_s end end
existing_file_tag()
click to toggle source
# 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 + file_preview_and_remove_button end end
file_exists?()
click to toggle source
# File lib/simple_form_extension/file_concern.rb, line 49 def file_exists? @file_exists ||= object.try(:"#{ attribute_name }?") || object.try(attribute_name).try(:attached?) end
file_url()
click to toggle source
# File lib/simple_form_extension/file_concern.rb, line 54 def file_url if object.try(:"#{ attribute_name }?") object.send(attribute_name) elsif object.try(attribute_name).try(:attached?) object.try(attribute_name).try(:service_url) end end
remove_attachment_method()
click to toggle source
# File lib/simple_form_extension/file_concern.rb, line 45 def remove_attachment_method options[:remove_method] || :"remove_#{ attribute_name }" end