From 9daf39ec5242a6a87efb9c862952e176d4314856 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Fri, 29 Feb 2008 19:46:58 +0000 Subject: Adds an optional description to attachments. git-svn-id: http://redmine.rubyforge.org/svn/trunk@1180 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/application.rb | 20 ++++++++++++-------- app/controllers/documents_controller.rb | 2 ++ 2 files changed, 14 insertions(+), 8 deletions(-) (limited to 'app/controllers') 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] -- cgit v1.2.3