add attachment model and add paperclip

This commit is contained in:
Reinier Balt 2014-07-03 23:21:39 +02:00
parent 013b260a1b
commit 76de5bf2b3
8 changed files with 78 additions and 22 deletions

10
app/models/attachment.rb Normal file
View file

@ -0,0 +1,10 @@
class Attachment < ActiveRecord::Base
belongs_to :todo, touch: true
has_attached_file :file,
url: '/:class/:id/:basename.:extension',
path: ":rails_root/db/assets/#{Rails.env}/:class/:id/:basename.:extension"
do_not_validate_attachment_file_type :file
# validates_attachment_content_type :file, :content_type => ["text/plain"]
end

View file

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