Ollie.marshall1-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org
2009-Nov-15 16:12 UTC
Rake task syntax help
Hi all, I am currently working on writing a script for a image archive web app and need a little help. The script needs to import a load of images, from one of two locations given by a XML feed. Most of it is sorted, except choosing the appropriate location of the image. The XML feed simply stores the file name of the image but not the full path. The image can come from two locations either "http://www.tistore.co.uk/assets/images/HiRes/# {product.image}.jpg" (High Resolution) or "http://www.tistore.co.uk/ assets/images/300-200/#{product.image}.gif" (Low Resolution). The first will be where a high resolution version is available and the second a low resolution. There will definitely be a low resolution image however I need the script to check whether high resolution version is available if so use it as this is the preferred version if possible. This is what i''ve got so far: [code] @image = Image.new unless product.image.empty? if product.image == ''noimage'' && ''NOIMAGE'' puts "No Image - SKIP" else [@image.image_file_url = "http://www.tistore.co.uk/assets/images/HiRes/ #{product.image}.jpg"] rescue OpenURI::HTTPError [@image.image_file_url = "http://www.tistore.co.uk/assets/images/ 300-200/#{product.image}.gif"] #this is where the problem lies end end @image.save [/code] The script needs to first check the High resolution location (http:// www.tistore.co.uk/assets/images/300-200/#{product.image}.gif") but if there is a 404 Not Found error(OpenURI::HTTPError) revert to the low resolution location (http://www.tistore.co.uk/assets/images/HiRes/# {product.image}.jpg). If anyone has any suggestions on the syntax to achieve this, all help appreciated! Thanks Ollie