module Struggle::ModelExtend
Public Instance Methods
delete_image(field)
click to toggle source
# File lib/struggle/concerns/model_extend.rb, line 33 def delete_image(field) unless self[field.to_sym].blank? begin File.delete("#{Rails.root}/public/#{self[field.to_sym]}") rescue puts "#{$!}" end end end
to_hash()
click to toggle source
# File lib/struggle/concerns/model_extend.rb, line 17 def to_hash obj = self.serializable_hash obj.each do |k, v| if v.class == ActiveSupport::TimeWithZone obj[k] = v.localtime.to_s(:db) end end obj end
upload_crop_image(field, image, x, y, w, h)
click to toggle source
# File lib/struggle/concerns/model_extend.rb, line 27 def upload_crop_image(field, image, x, y, w, h) filepath = "uploads/#{self.class.table_name}/#{Time.now.to_date.strftime("%Y%m%d")}" file = Struggle::Tfile.imagecropupload(image, "#{Rails.root}/public/#{filepath}/","jpg|bmp|gif|ico|pcx|jpeg|tif|png", 0, 2000, x, y, w, h) self[field.to_sym] = file[:state] ? "#{filepath}/#{file[:result]}" : "" end