Sha256: 6a414da6ffa67ff385d06788d707047adc0771d7abd1a44cf3221b835dd04e1b

Contents?: true

Size: 823 Bytes

Versions: 4

Compression:

Stored size: 823 Bytes

Contents

module Droom
  class DocumentAttachment < ActiveRecord::Base
    attr_accessible :attachee, :document, :agenda_section, :category_id
    
    belongs_to :document
    belongs_to :attachee, :polymorphic => true
    belongs_to :category
    belongs_to :created_by, :class_name => "Droom::User"

    def slug
      if attachee 
        attachee.slug
      else
        'Unattached'
      end
    end
    
    def category_name
      category ? category.name : "uncategorised"
    end
  
    def move_document_to_folder
      recipient = if category
        # attachee will be an event
        attachee.find_or_create_agenda_category(category)
      else
        attachee
      end
      if document
        document.folder = nil
        recipient.receive_document(document)
        document.save
      end
    end
  
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
droom-0.4.3 app/models/droom/document_attachment.rb
droom-0.4.2 app/models/droom/document_attachment.rb
droom-0.4.1 app/models/droom/document_attachment.rb
droom-0.2.1 app/models/droom/document_attachment.rb