summaryrefslogtreecommitdiffstats
path: root/app/controllers
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2008-02-29 19:46:58 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2008-02-29 19:46:58 +0000
commit9daf39ec5242a6a87efb9c862952e176d4314856 (patch)
tree78ac3c4012e88e4f907e0d5a075956402af67684 /app/controllers
parent4b15dc10c10d9cb54d156457cc7d6823dac55520 (diff)
downloadredmine-9daf39ec5242a6a87efb9c862952e176d4314856.tar.gz
redmine-9daf39ec5242a6a87efb9c862952e176d4314856.zip
Adds an optional description to attachments.
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1180 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/application.rb20
-rw-r--r--app/controllers/documents_controller.rb2
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]