If I have, for example, an image that pass all the validations, like, size, dimensions, type, etc, but when I have to process it, for some unknown reason ImageMagick throws an error anyway… how should I handle that?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
For Rails 4 and earlier the Active Record Validations and Callbacks Guide:
So you can either let the exception bubble up into ActiveRecord or you can trap it yourself, translate it to something that makes sense within the context of your application, and return
false. You can register errors inside abefore_savecallback so something like this might make sense:If you can translate the ImageMagick errors into something that makes sense to the end user then trapping and translating the ImageMagick exception (as in
do_magick_things) would probably make the most sense; converting the exception into an error message also allows the caller to usesave!if they want exceptions orsaveif they don’t.