Ajax file upload to tmp dir. Add cached_attachment to document. Recover image from cache. Add progress bar.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user