Module: FileDelete::ViewHelpers

Defined in:
lib/paperclip_delete_helpers.rb

Instance Method Summary collapse

Instance Method Details

#is_image(content_type) ⇒ Object



95
96
97
98
99
100
101
# 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 = {}) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# 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