Module: Admin::Resources::DataTypes::PaperclipHelper

Defined in:
app/helpers/admin/resources/data_types/paperclip_helper.rb

Instance Method Summary collapse

Instance Method Details



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/helpers/admin/resources/data_types/paperclip_helper.rb', line 8

def link_to_detach_attribute_for_paperclip(attribute)
  validators = @item.class.validators.delete_if { |i| i.class != ActiveModel::Validations::PresenceValidator }.map(&:attributes).flatten.map(&:to_s)
  attachment = @item.send(attribute)

  if attachment.exists? && !validators.include?("#{attribute}_file_name") && attachment
    attribute_i18n = @item.class.human_attribute_name(attribute)
    label_text = <<-HTML
#{attribute_i18n}
<small>#{link_to Typus::I18n.t("Remove"), { :action => 'update', :id => @item.id, :_nullify => attribute, :_continue => true }, :confirm => Typus::I18n.t("Are you sure?")}</small>
    HTML
    label_text.html_safe
  end
end

#table_paperclip_field(attribute, item) ⇒ Object



3
4
5
6
# File 'app/helpers/admin/resources/data_types/paperclip_helper.rb', line 3

def table_paperclip_field(attribute, item)
  options = { :width => 25 }
  typus_paperclip_preview(item, attribute, options)
end

#typus_paperclip_preview(item, attachment, options = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/helpers/admin/resources/data_types/paperclip_helper.rb', line 22

def typus_paperclip_preview(item, attachment, options = {})
  if (data = item.send(attachment)).exists?
    styles = data.styles.keys
    if data.content_type =~ /^image\/.+/ && styles.include?(Typus.file_preview) && styles.include?(Typus.file_thumbnail)
      render "admin/templates/paperclip_preview",
             :preview => data.url(Typus.file_preview, false),
             :thumb => data.url(Typus.file_thumbnail, false),
             :options => options
    else
      link_to data.original_filename, data.url(:original, false)
    end
  end
end