Module: PaperclipI18n::ActsAsAttachment::InstanceMethods
- Defined in:
- lib/paperclip_i18n/acts_as_attachment.rb
Instance Method Summary collapse
-
#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.
- #browser_safe? ⇒ Boolean (also: #web_safe?)
- #content_type ⇒ Object
- #detach(attached) ⇒ Object
-
#icon ⇒ Object
This method assumes you have images that corespond to the filetypes.
- #name ⇒ Object
- #size ⇒ Object
- #url(*args) ⇒ Object
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?
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_type ⇒ Object
33 34 35 |
# File 'lib/paperclip_i18n/acts_as_attachment.rb', line 33 def content_type upload_content_type end |
#detach(attached) ⇒ Object
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 |
#icon ⇒ Object
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 |
#name ⇒ Object
29 30 31 |
# File 'lib/paperclip_i18n/acts_as_attachment.rb', line 29 def name upload_file_name end |
#size ⇒ Object
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 |