Module: Watarase::ImageHolder::Store

Defined in:
lib/watarase/image_holder.rb

Instance Method Summary collapse

Instance Method Details

#prepare_imageObject



37
38
39
40
41
42
# File 'lib/watarase/image_holder.rb', line 37

def prepare_image
  puts "**** prepare_image ****"
  return unless @data
  self.image_data = Magick::Image.from_blob(@data).first.resize_to_fit(100, 100).to_blob
  self.image_thumb = Magick::Image.from_blob(@data).first.thumbnail(35, 35).to_blob
end

#uploaded_image=(image_params) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/watarase/image_holder.rb', line 23

def uploaded_image= (image_params)
  puts "**** uploaded_image ****"
  if image_params[:remove_image] && image_params[:remove_image] == "1"
    self.destroy
  elsif image_params[:image_file] && !image_params[:image_file].blank?
    self.filename = image_params[:image_file].original_filename
    @image_filename = self.filename
    self.content_type = image_params[:image_file].content_type
    @data = image_params[:image_file].tempfile.read
  elsif self.new_record?
    self.destroy
  end
end