lib/active_metadata/persistence/attachment.rb in active_metadata-0.7.0 vs lib/active_metadata/persistence/attachment.rb in active_metadata-0.7.1

- old
+ new

@@ -4,13 +4,20 @@ receiver.send :include, InstanceMethods end module InstanceMethods - def save_attachment_for(field, file, starred=false) - attachment = ActiveMetadata::Attachment.create! :document_class => metadata_class, :document_id => metadata_id, :label => field, :attach => file, - :starred => starred, :created_by => current_user_id + def save_attachment_for(field, file, starred=false, group=nil) + attachment = ActiveMetadata::Attachment.create!( + :document_class => metadata_class, + :document_id => metadata_id, + :label => field, + :attach => file, + :starred => !!starred, + :created_by => current_user_id, + :group => group) + reload_attachments_cache_for field self.send(:send_notification, field, "", attachment.attach.original_filename, :attachment_message, current_user_id) end def attachments_for(field, order_by="updated_at DESC") @@ -27,14 +34,15 @@ self.send(:send_notification, a.label, filename, "", :attachment_message) end def update_attachment(id, newfile, starred=nil) a = ActiveMetadata::Attachment.find(id) + puts a old_filename = a.attach.original_filename a.attach = newfile a.updated_by = current_user_id a.starred = starred if !starred.nil? - a.save + a.save! new_filename = a.attach.original_filename reload_attachments_cache_for a.label self.send(:send_notification, a.label, old_filename, new_filename, :attachment_message, current_user_id) end