Hi all!
I have a problem with the validation of uploaded images, or, to be more
specific, with raising errors from plug-in files. I am using
UploadColumn to upload pictures. Problem is that it won’t raise errors
when upload e.g. txt-files. It will say “Upload succesfull”, the
time-stamp is updated only the picture hasn’t changed.
I looked through the code of the plugin and found:
#----File: upload_column.rb
#----Code
[begin]--------------------------------------------------------------------------------------------------------------------------------------
# Note also that unlike RMagicks’s read, this method will return nil
if the image cannot
# be opened, it will not throw an Error, so you can happily
# apply this, even if you aren’t sure that the file is an image.
#
# +process!+ is usually more useful, don’t use +procesrs+ unless
there is a good reason to!
#
# Remember to call GC.start after you are done processing the image,
to avoid memory leaks.
def process
# Load the file as a ImageMagick object, pass to block, return the
yielded result
begin
img = ::Magick::Image::read(self.path).first
rescue Magick::ImageMagickError
return nil
end
yield( img )
end
#----Code
[end]----------------------------------------------------------------------------------------------------------------------------------------
Now I guess I’d just have to raise an error message substituting “return
nilâ€. Is that right? If so, how can I do that? I experimented a bit
around but with no success.
Hope you can help me! Big thanks in advance!
bluescript