mirror of
https://github.com/ENSL/ensl.org.git
synced 2024-12-27 04:51:14 +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
|
end
|
||||||
|
|
||||||
# Update the path on creation
|
# 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
|
# Move the file if it has moved
|
||||||
if !new_record? and directory_id_changed? and File.exists?(name.current_path)
|
if !new_record? and directory_id_changed? and File.exists?(path)
|
||||||
FileUtils.mv(location, 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
|
end
|
||||||
|
|
||||||
if description.nil? or description.empty?
|
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:
|
# This is a sensible default for uploaders that are meant to be mounted:
|
||||||
def store_dir
|
def store_dir
|
||||||
if model and model.directory
|
if model and model.directory
|
||||||
|
# This is a recursive look up
|
||||||
model.directory.full_path
|
model.directory.full_path
|
||||||
else
|
else
|
||||||
Directory.find(Directory::ROOT).full_path
|
Directory.find(Directory::ROOT).full_path
|
||||||
|
|
Loading…
Reference in a new issue