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