Ok, I have file column set up and working for a model ... my file gets
uploaded no problem. I need to do some processing on the file after
save, though (it is a zip file) and can''t seem to get a handle on how
to
access the uploaded file. I am trying to add a method to the model
called process_upload and I am not sure how to get the location of the
uploaded file relative to RAILS_ROOT.
--
class PhotoSet < ActiveRecord::Base
has_many :photo_set_item
file_column :file, :root_path => File.join(RAILS_ROOT,
"uploaded")
def process_upload
breakpoint
zip_file = self.file.absolute_path # does not work, what does??
if File.exist?(zip_file)
# change to zip_file dir
cwd = Dir.pwd
Dir.chdir(File.dirname(zip_file))
# unzip file
tmpdir = File.basename(zip_file, ".zip")
Fileutils::mkdir(tmpdir)
Dir.chdir(tmpdir)
Zip::ZipFile.open("../#{File.basename(zip_file)}") {|zr|
zr.foreach {|entry| zr.extract(entry, Dir.pwd) }
}
# restore original working dir
Dir.chdir(cwd)
end
return true
end
end
--
Debugging via breakpointer has just confused me further, as I can''t
really tell what context I am in. I can see what my local and instance
variables are but... is that it? Can I step through my code? *sigh*
Also, can I manipulate children of the current model (set via has_many)
from within the model? I need to create new children based on the
contents of the uploaded zip file... Should I be doing this stuff in the
model anyway?
Please, someone shed some light on this for me...
--
Tim Ferrell
Systems Engineer
McGee Corporation
P.O. Box 1375
Matthews, NC 28106
1-704-882-1500 x374 (phone)
1-704-882-3263 (fax)
1-980-721-1912 (cell)