Structure legal documents directory #2667

This commit is contained in:
Martin Lensment 2015-06-29 16:51:01 +03:00
parent 72bb02825d
commit cce185cf9d

View file

@ -15,7 +15,10 @@ class LegalDocument < ActiveRecord::Base
loop do
rand = SecureRandom.random_number.to_s.last(4)
next if rand.to_i == 0 || rand.length < 4
self.path = "#{ENV['legal_documents_dir']}/#{Time.zone.now.to_formatted_s(:number)}_#{rand}.#{document_type}"
dir = "#{ENV['legal_documents_dir']}/#{Time.zone.now.strftime('%Y/%m/%d')}"
FileUtils.mkdir_p(dir)
self.path = "#{dir}/#{Time.zone.now.to_formatted_s(:number)}_#{rand}.#{document_type}"
break unless File.file?(path)
end