make attachments accesible from user model and fix cleaning up attachment on destroy

This commit is contained in:
Reinier Balt 2014-07-17 12:55:30 +02:00
parent 8d9f07f57b
commit a28edbd5d6
5 changed files with 40 additions and 7 deletions

View file

@ -817,14 +817,12 @@ class TodosController < ApplicationController
def attachment
id = params[:id]
filename = params[:filename]
attachment = Attachment.where(id: id).first
attachment = current_user.attachments.find(id)
if attachment
if attachment.todo.user == current_user
send_file(attachment.file.path)
else
head :forbidden
end
send_file(attachment.file.path,
disposition: 'attachment',
type: 'message/rfc822')
else
head :not_found
end