Module: FileDelete::ViewHelpers

Defined in:
lib/paperclip_delete_helpers.rb

Instance Method Summary collapse

Instance Method Details

#is_image(content_type) ⇒ Object



93
94
95
96
97
98
99
# File 'lib/paperclip_delete_helpers.rb', line 93

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 = {}) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/paperclip_delete_helpers.rb', line 74

def show_paperclip_attachment(f, object, method, deletable=true, options = {})
  res = ""
  if object.send(method).send(:exists?)
    content_type = object.send("#{method.to_s}_content_type".to_sym)
    if is_image content_type
      res += image_tag(object.send(method).send(:url), :width => "200px")
    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