Module: ActiveMetadata::Persistence::ActiveRecord::Attachment::InstanceMethods
- Defined in:
- lib/active_metadata/persistence/active_record/attachment.rb
Instance Method Summary collapse
- #attachments_for(field) ⇒ Object
- #delete_attachment_for(field, id) ⇒ Object
- #has_attachments_for(field) ⇒ Object
- #save_attachment_for(field, file) ⇒ Object
- #update_attachment_for(field, id, newfile) ⇒ Object
Instance Method Details
#attachments_for(field) ⇒ Object
15 16 17 18 19 |
# File 'lib/active_metadata/persistence/active_record/attachment.rb', line 15 def (field) Rails.cache.fetch((field), :expires_in => ActiveMetadata::CONFIG['cache_expires_in'].minutes) do field end end |
#delete_attachment_for(field, id) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/active_metadata/persistence/active_record/attachment.rb', line 21 def (field,id) a = Attachment.find(id) filename = a.attach.original_filename a.destroy field self.send(:send_notification, field, filename, "", :attachment_message) end |
#has_attachments_for(field) ⇒ Object
41 42 43 |
# File 'lib/active_metadata/persistence/active_record/attachment.rb', line 41 def field (field).size == 0 ? false : true end |
#save_attachment_for(field, file) ⇒ Object
9 10 11 12 13 |
# File 'lib/active_metadata/persistence/active_record/attachment.rb', line 9 def (field, file) = Attachment.create! :document_class => , :document_id => , :label => field, :attach => file, :created_by => current_user_id field self.send(:send_notification, field, "", .attach.original_filename, :attachment_message, current_user_id) end |
#update_attachment_for(field, id, newfile) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/active_metadata/persistence/active_record/attachment.rb', line 29 def (field, id, newfile) a = Attachment.find(id) old_filename = a.attach.original_filename a.attach = newfile a.updated_by = current_user_id a.save new_filename = a.attach.original_filename field self.send(:send_notification, field, old_filename, new_filename, :attachment_message, current_user_id) end |