# model class# define attr_accessor coordsclassUser<ActiveRecord::Baseattr_accessor:coordsmount_uploader:icon,AvatarUploaderend# controller# pass the params to @user.coordsdefcrop_icon@user.coords=params[:coords]@user.icon=File.open(path)@user.saveredirect_to:action=>'basic'end# Uploader# the model in the function is same as @user in controll,# and can be invoked inside of process method defcrop_areamanipulate!do|img|unlessmodel.coords.nil?coords=JSON.parse(model.coords)img.crop("#{coords['w']}x#{coords['h']}+#{coords['x']}+#{coords['y']}")endimg=yield(img)ifblock_given?imgendend