diff options
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/application.rb | 20 | ||||
-rw-r--r-- | app/controllers/documents_controller.rb | 2 |
2 files changed, 14 insertions, 8 deletions
diff --git a/app/controllers/application.rb b/app/controllers/application.rb index 3644c396a..7510d503e 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -160,16 +160,20 @@ class ApplicationController < ActionController::Base end # TODO: move to model - def attach_files(obj, files) - attachments = [] - if files && files.is_a?(Array) - files.each do |file| - next unless file.size > 0 - a = Attachment.create(:container => obj, :file => file, :author => User.current) - attachments << a unless a.new_record? + def attach_files(obj, attachments) + attached = [] + if attachments && attachments.is_a?(Hash) + attachments.each_value do |attachment| + file = attachment['file'] + next unless file && file.size > 0 + a = Attachment.create(:container => obj, + :file => file, + :description => attachment['description'].to_s.strip, + :author => User.current) + attached << a unless a.new_record? end end - attachments + attached end # Returns the number of objects that should be displayed diff --git a/app/controllers/documents_controller.rb b/app/controllers/documents_controller.rb index 93f25c495..7e732b9b6 100644 --- a/app/controllers/documents_controller.rb +++ b/app/controllers/documents_controller.rb @@ -21,6 +21,8 @@ class DocumentsController < ApplicationController before_filter :find_document, :except => [:index, :new] before_filter :authorize + helper :attachments + def index @sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category' documents = @project.documents.find :all, :include => [:attachments, :category] |