Module: Polypaperclip::InstanceMethods

Defined in:
lib/polypaperclip.rb

Instance Method Summary collapse

Instance Method Details

#each_attachmentObject

we override Paperclip’s each_attachment so that we proxy through the attachments model



73
74
75
76
77
# File 'lib/polypaperclip.rb', line 73

def each_attachment
  self.class.polypaperclip_definitions.each do |name, definition|
    yield(name, paperclip_attachment_for(name))
  end
end

#paperclip_attachment_for(name) ⇒ Object



90
91
92
93
94
95
# File 'lib/polypaperclip.rb', line 90

def paperclip_attachment_for(name)
  @_paperclip_attachments ||= {}
  @_paperclip_attachments[name] ||= Polypaperclip::Attachment.new(name, 
    self, 
    self.class.polypaperclip_definitions[name])
end

#save_attached_filesObject



79
80
81
82
83
84
85
86
87
88
# File 'lib/polypaperclip.rb', line 79

def save_attached_files
  #premptively save each attachment
  Paperclip.log("Saving attachments.")
  each_attachment do |name, attachment|
    if attachment && attachment.instance
      attachment.instance.save
      attachment.send(:save)
    end
  end
end