Module: Griddle::HasGridAttachment::InstanceMethods

Defined in:
lib/griddle/has_grid_attachment.rb

Instance Method Summary collapse

Instance Method Details

#attachment_for(name, options = {}) ⇒ Object



34
35
36
37
# File 'lib/griddle/has_grid_attachment.rb', line 34

def attachment_for name, options = {}
  @_gripster_attachments ||= {}
  @_gripster_attachments[name] ||= Attachment.for(name, self, options)
end

#destroy_attached_filesObject



39
40
41
# File 'lib/griddle/has_grid_attachment.rb', line 39

def destroy_attached_files
  each_attachment{|name, attachment| attachment.destroy }
end

#each_attachmentObject



43
44
45
46
47
# File 'lib/griddle/has_grid_attachment.rb', line 43

def each_attachment
  self.class.attachment_definitions.each do |name, definition|
    yield(name, attachment_for(name))
  end
end

#save_attached_filesObject



49
50
51
52
53
54
# File 'lib/griddle/has_grid_attachment.rb', line 49

def save_attached_files
  each_attachment do |name, attachment|
    attachment.owner_id = self.id
    attachment.send(:save) unless attachment.nil?
  end
end