1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- module ApplicationModel::HasAttachments
- extend ActiveSupport::Concern
- included do
- after_create :attachments_buffer_check
- after_update :attachments_buffer_check
- end
- def attachments
- Store.list(object: self.class.to_s, o_id: id)
- end
- def attachments=(attachments)
- self.attachments_buffer = attachments
-
- return if !(id&.nonzero?)
- attachments_buffer_check
- end
- private
- def attachments_buffer
- @attachments_buffer_data
- end
- def attachments_buffer=(attachments)
- @attachments_buffer_data = attachments
- end
- def attachments_buffer_check
-
- return 1 if attachments_buffer.nil?
-
- article_store = []
- attachments_buffer.each do |attachment|
- article_store.push Store.add(
- object: self.class.to_s,
- o_id: id,
- data: attachment.content,
- filename: attachment.filename,
- preferences: attachment.preferences,
- created_by_id: created_by_id,
- )
- end
- attachments_buffer = nil
- end
- end
|