destroy static file after destroy asset
This commit is contained in:
parent
0f7dce8aa6
commit
8f5c6d1a56
|
@ -10,11 +10,16 @@ class Asset
|
||||||
|
|
||||||
before_validation :setup_filename
|
before_validation :setup_filename
|
||||||
after_save :save_static_file
|
after_save :save_static_file
|
||||||
|
after_destroy :delete_static_file
|
||||||
|
|
||||||
def url
|
def url
|
||||||
"/assets/#{self.filename}"
|
"/assets/#{self.filename}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def location
|
||||||
|
"#{RAILS_ROOT}/public/assets/#{self.filename}"
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def setup_filename
|
def setup_filename
|
||||||
|
@ -24,9 +29,13 @@ class Asset
|
||||||
end
|
end
|
||||||
|
|
||||||
def save_static_file
|
def save_static_file
|
||||||
f = File.new("#{RAILS_ROOT}/public/assets/#{self.filename}", "wb")
|
f = File.new(self.location, "wb")
|
||||||
f.write(self.data.file.read)
|
f.write(self.data.file.read)
|
||||||
f.close
|
f.close
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def delete_static_file
|
||||||
|
File.delete(self.location) rescue nil
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
Loading…
Reference in New Issue