mirror of
https://github.com/ENSL/ensl.org.git
synced 2024-12-26 04:21:36 +00:00
Update data_file correctly on recreate
This commit is contained in:
parent
2297e8c4d1
commit
8b2ce91625
2 changed files with 7 additions and 5 deletions
|
@ -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?
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue