Module: PaperclipI18n::ActsAsAttachment::InstanceMethods

Defined in:
lib/paperclip_i18n/acts_as_attachment.rb

Instance Method Summary collapse

Instance Method Details

#attachable_type=(sType) ⇒ Object

Rails doc says: Using polymorphic assocs with STI can be a little tricky –> read more @ api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html



60
61
62
# File 'lib/paperclip_i18n/acts_as_attachment.rb', line 60

def attachable_type=(sType)
  super(sType.to_s.classify.constantize.base_class.to_s)
end

#browser_safe?Boolean Also known as: web_safe?

Returns:

  • (Boolean)


41
42
43
# File 'lib/paperclip_i18n/acts_as_attachment.rb', line 41

def browser_safe?
  %w(jpg gif png).include?(url.split('.').last.sub(/\?.+/, '').downcase)
end

#content_typeObject



33
34
35
# File 'lib/paperclip_i18n/acts_as_attachment.rb', line 33

def content_type
  upload_content_type
end

#detach(attached) ⇒ Object

Raises:

  • (::ActiveRecord::RecordNotFound)


52
53
54
55
56
# File 'lib/paperclip_i18n/acts_as_attachment.rb', line 52

def detach(attached)
  a = attachings.find(:first, :conditions => ['attachable_id = ? AND attachable_type = ?', attached, attached.class.to_s])
  raise(::ActiveRecord::RecordNotFound) unless a
  a.destroy
end

#iconObject

This method assumes you have images that corespond to the filetypes. For example “image/png” becomes “image-png.png”



48
49
50
# File 'lib/paperclip_i18n/acts_as_attachment.rb', line 48

def icon
  "#{upload_content_type.gsub(/[\/\.]/,'-')}.png"
end

#nameObject



29
30
31
# File 'lib/paperclip_i18n/acts_as_attachment.rb', line 29

def name
  upload_file_name
end

#sizeObject



37
38
39
# File 'lib/paperclip_i18n/acts_as_attachment.rb', line 37

def size
  upload_file_size
end

#url(*args) ⇒ Object



25
26
27
# File 'lib/paperclip_i18n/acts_as_attachment.rb', line 25

def url(*args)
  upload.url(*args)
end