Forum: Ruby on Rails Problem using rmagick in model class

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
David R. (Guest)
on 2005-12-12 20:07
(Received via mailing list)
I'm refactoring some code in order to conform to "the right way" of
doing
things. That is, I'm moving my image-saving code from my controller to
my
model. What worked fine in the controller class is not working in the
model
class.

Currently, my code looks somewhat like this:
##############
class RegistrantsController < ApplicationController
  def upload_image
    @registrant = Registrant.find(session[:registrant_id])
    if request.post?
      if(params[:crop_params])
        @registrant.save_image(params[:image_to_crop],
params[:crop_params])
        redirect_to :action => :index
      else
        @registrant.image = params[:registrant][:image]
        File.chmod(0644, @registrant.image)
      end
    end
  end
end

class Registrant < ActiveRecord::Base
  require_gem 'rmagick'

  def save_image(image_to_crop, crop_params)

    img_base = RAILS_ROOT + "/public/images/registrants/"
    img_file =  self.id.to_s + ".jpg"
    y, x, w, h = crop_params.split(',')

    img = Magick::ImageList.new(image_to_crop) # this is throwing
"uninitialized constant ImageList"

    img.crop!(x.to_i, y.to_i, w.to_i, h.to_i)
    img.resize!(120, 120)
    color_thumb = img.resize(32, 32)
    grey_img = img.quantize(256, Magick::GRAYColorspace)
    img.write(img_path + img_filename)
    grey_img.write(img_base + 'greyscale/' + img_filename)
    color_thumb.write(img_base + 'thumbnail/' + img_filename)
  end
end
##############

Note the comment in there (# this is throwing "uninitialized constant
ImageList")

Can anyone see what I've done wrong, or otherwise help out?

Thanks,
David R.
This topic is locked and can not be replied to.