mirror of
https://github.com/internetee/registry.git
synced 2025-07-21 18:26:06 +02:00
Save documents on disk
This commit is contained in:
parent
a99d36f683
commit
79f76b2ccf
6 changed files with 41 additions and 6 deletions
|
@ -3,4 +3,19 @@ class LegalDocument < ActiveRecord::Base
|
|||
belongs_to :documentable, polymorphic: true
|
||||
|
||||
TYPES = %w(pdf bdoc ddoc zip rar gz tar 7z)
|
||||
|
||||
attr_accessor :body
|
||||
|
||||
before_save :save_to_filesystem
|
||||
def save_to_filesystem
|
||||
loop do
|
||||
rand = SecureRandom.random_number.to_s.last(4)
|
||||
self.path = "#{ENV['legal_documents_dir']}/#{Time.zone.now.to_formatted_s(:number)}_#{rand}.#{document_type}"
|
||||
break unless File.file?(path)
|
||||
end
|
||||
|
||||
# TODO: Change path for test env
|
||||
File.open(path, 'wb') { |f| f.write(Base64.decode64(body)) } unless Rails.env.test?
|
||||
self.path = path
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue