lib/tori/rails.rb in tori-0.0.2 vs lib/tori/rails.rb in tori-0.0.3
- old
+ new
@@ -7,25 +7,22 @@
# Filename hash usgin `id` attribute by default.
# And you can change this attribute, But it's should be record unique.
#
# @example:
# class Photo < ActiveRecord::Base
- # tori :image, id: :id
+ # tori :image
# end
def tori(name)
super
- name_hash_get = "#{name}_hash".to_sym
-
after_save do
- uploader = __send__ name
- filename = __send__ name_hash_get
- Tori.config.backend.copy(uploader.path, filename) if uploader && filename
+ file = __send__ name
+ Tori.config.backend.copy(file.from.path, file.to_s) if file.from && file.copy?
end
after_destroy do
- filename = __send__ name_hash_get
- Tori.config.backend.delete(filename) if filename
+ file = __send__ name
+ Tori.config.backend.delete(file.to_s) if file.exist?
end
end
end
end
::ActiveRecord::Base.extend(Tori::ActiveRecord)