module FileDelete::ViewHelpers

Public Instance Methods

is_image(content_type) click to toggle source
# File lib/paperclip_delete_helpers.rb, line 95
def is_image(content_type)
  if ['image/jpeg', 'image/png', 'image/gif','image/pjpeg'].include? content_type
    true
  else
    false
  end
end
show_paperclip_attachment(f, object, method, deletable=true, options = {}, formtastic_options = {}) click to toggle source
# File lib/paperclip_delete_helpers.rb, line 74
def show_paperclip_attachment(f, object, method, deletable=true, options = {}, formtastic_options = {})
  res = ""
  if object.send(method).send(:exists?)
    content_type = object.send("#{method.to_s}_content_type".to_sym)
    if is_image content_type
      width = options[:width].nil? ? "200px" : options[:width]
      height = options[:height].nil? ? "" : options[:height]
      res += image_tag(object.send(method).send(:url), :width => width, :height => height)
    else
      res += link_to(object.send("#{method.to_s}_file_name".to_sym), object.send(method).send(:url), {:target => "_blank"})
    end
    if deletable 
      res += f.input "delete_#{method.to_s}".to_sym, :as => :boolean, :label => t('general.delete_file')

    end
  end
  res += f.input method, :as => :file, :input_html => options

  res
end