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

@ -7,4 +7,14 @@ class Attachment < ActiveRecord::Base
do_not_validate_attachment_file_type :file
# validates_attachment_content_type :file, :content_type => ["text/plain"]
before_destroy :delete_attached_file
private
def delete_attached_file
file = nil
save!
end
end

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' }

View file

@ -96,6 +96,7 @@ class User < ActiveRecord::Base
has_many :notes, -> { order "created_at DESC" }, dependent: :delete_all
has_one :preference, dependent: :destroy
has_many :attachments, through: :todos
validates_presence_of :login
validates_presence_of :password, if: :password_required?