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
|
||||
after_save :save_static_file
|
||||
after_destroy :delete_static_file
|
||||
|
||||
def url
|
||||
"/assets/#{self.filename}"
|
||||
end
|
||||
|
||||
def location
|
||||
"#{RAILS_ROOT}/public/assets/#{self.filename}"
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def setup_filename
|
||||
|
@ -24,9 +29,13 @@ class Asset
|
|||
end
|
||||
|
||||
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.close
|
||||
end
|
||||
|
||||
def delete_static_file
|
||||
File.delete(self.location) rescue nil
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue