Ensure correct extension when downloading documents
This commit is contained in:
parent
7d112516a1
commit
957b347b04
2 changed files with 16 additions and 5 deletions
|
|
@ -2,4 +2,19 @@ class Document < ActiveRecord::Base
|
|||
belongs_to :created_by, :class_name => 'User', :foreign_key => 'created_by_user_id'
|
||||
|
||||
validates_presence_of :data
|
||||
|
||||
def filename
|
||||
types = MIME::Types[mime]
|
||||
|
||||
if name.include? '.'
|
||||
types.each do |type|
|
||||
type.extensions.each do |extension|
|
||||
return name if name.end_with? ".#{extension}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
"#{name}.#{types.first.preferred_extension}"
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue