diff --git a/app/models/legal_document.rb b/app/models/legal_document.rb index 0972767f7..f1a63e976 100644 --- a/app/models/legal_document.rb +++ b/app/models/legal_document.rb @@ -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