move logic to use latest image file attachment to class method for common use (#3261)

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@7908 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Toshi MARUYAMA
2011-11-24 05:31:29 +00:00
parent 627dfd80b6
commit 564321b2d5
3 changed files with 30 additions and 4 deletions
+6
View File
@@ -167,6 +167,12 @@ class Attachment < ActiveRecord::Base
{:files => attached, :unsaved => obj.unsaved_attachments}
end
def self.latest_attach(attachments, filename)
attachments.sort_by(&:created_on).reverse.detect {
|att| att.filename.downcase == filename.downcase
}
end
private
def sanitize_filename(value)
# get only the filename, not the whole path