Ajax file upload to tmp dir. Add cached_attachment to document. Recover image from cache. Add progress bar.

This commit is contained in:
Senén Rodero Rodríguez
2017-08-01 00:48:24 +02:00
parent 9a0b34fffe
commit e327b420ff
7 changed files with 64 additions and 66 deletions

View File

@@ -2,11 +2,14 @@ class Document < ActiveRecord::Base
include DocumentsHelper
include DocumentablesHelper
has_attached_file :attachment
attr_accessor :cached_attachment
belongs_to :user
belongs_to :documentable, polymorphic: true
validates_attachment :attachment, presence: true
# validates_attachment :attachment, presence: true
validate :attachment_presence
# validates :attachment_prensence
# Disable paperclip security validation due to polymorphic configuration
# Paperclip do not allow to user Procs on valiations definition
do_not_validate_attachment_file_type :attachment
@@ -35,4 +38,10 @@ class Document < ActiveRecord::Base
end
end
def attachment_presence
if attachment.blank? && cached_attachment.blank?
errors[:attachment] = I18n.t("errors.messages.blank")
end
end
end