From 8b2ce91625090e437422c009a7c78d7ebb26a58d Mon Sep 17 00:00:00 2001 From: Ari Timonen Date: Mon, 6 Apr 2020 23:54:10 +0300 Subject: [PATCH] Update data_file correctly on recreate --- app/models/data_file.rb | 11 ++++++----- app/uploaders/file_uploader.rb | 1 + 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/models/data_file.rb b/app/models/data_file.rb index a57c54c..cfb363a 100644 --- a/app/models/data_file.rb +++ b/app/models/data_file.rb @@ -103,13 +103,14 @@ class DataFile < ActiveRecord::Base end # Update the path on creation - if path.nil? - self.path = File.join(directory.path, File.basename(name.to_s)) - end # Move the file if it has moved - if !new_record? and directory_id_changed? and File.exists?(name.current_path) - FileUtils.mv(location, path) + if !new_record? and directory_id_changed? and File.exists?(path) + FileUtils.mv(path, location) + end + + if path.nil? or directory_id_changed? + self.path = File.join(directory.full_path, File.basename(name.to_s)) end if description.nil? or description.empty? diff --git a/app/uploaders/file_uploader.rb b/app/uploaders/file_uploader.rb index 33cd0ca..1495ace 100644 --- a/app/uploaders/file_uploader.rb +++ b/app/uploaders/file_uploader.rb @@ -5,6 +5,7 @@ class FileUploader < CarrierWave::Uploader::Base # This is a sensible default for uploaders that are meant to be mounted: def store_dir if model and model.directory + # This is a recursive look up model.directory.full_path else Directory.find(Directory::ROOT).full_path