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 e38a7742f0
commit ed9f429d4a
2 changed files with 2 additions and 2 deletions

View file

@ -817,7 +817,7 @@ 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
send_file(attachment.file.path,

View file

@ -25,7 +25,7 @@ class Todo < ActiveRecord::Base
has_many :pending_successors, -> {where('todos.state = ?', 'pending')}, :through => :predecessor_dependencies,
:source => :successor
has_many :attachments, dependent: :delete_all
has_many :attachments, dependent: :destroy
# scopes for states of this todo
scope :active, -> { where state: 'active' }