Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 返回语句_Ruby_Ruby On Rails 3 - Fatal编程技术网

Ruby 返回语句

Ruby 返回语句,ruby,ruby-on-rails-3,Ruby,Ruby On Rails 3,后照片后处理:后处理后照片 def post_process_photo img = EXIFR::JPEG.new(photo.queued_for_write[:original].path) # error on this line return unless img self.width = img.width self.height = img.height self.model = img.model end 我正在使用一个名为EXIFR的ruby gem

后照片后处理:后处理后照片

 def post_process_photo
  img = EXIFR::JPEG.new(photo.queued_for_write[:original].path)  # error on this line
  return unless img

  self.width = img.width
  self.height = img.height
  self.model = img.model
end
我正在使用一个名为EXIFR的ruby gem,它从JPEG文件中提取EXIF数据。EXIF数据只是有关图片的技术数据。因此,当我上传JPEG时,我的代码工作正常,但是任何其他图像类型都会导致它崩溃

EXIFR::ImagesController#create中的格式错误

找不到图像标记的开始


我假设如果img变量没有赋值,return语句将允许此操作,但情况似乎并非如此。

您可以挽救错误并返回其他内容

def post_process_photo
  begin 
    img = EXIFR::JPEG.new(photo.queued_for_write[:original].path)  # error on this line
    self.width = img.width
    self.height = img.height
    self.model = img.model
  rescue EXIFR::MalformedJPEG
    return nil
  end
end