5

我有一个模型:

    mount_uploader :image, ImageUploader

上传图像时,我想从图像中检索一些宽度、高度和一些 EXIF 数据。在我调用的前置过滤器中,self.image.url但这将返回如下内容:

/uploads/tmp/20110630-1316-10507-7899/emerica_wildinthestreets.jpg

问题是当我尝试使用以下方法打开此图像时:

image = MiniMagick::Image.open(self.image.url)

我得到“没有这样的文件或目录 - /uploads/tmp/20110630-1312-10507-6638/emerica_wildinthestreets.jpg”。看起来图像已经从 tmp 文件夹移动到它的最终位置,但self.image.url没有反映这种变化。

我也试过这个after_save方法,但结果是一样的。有任何想法吗?

4

1 回答 1

5

原来我需要将“#{Rails.root.to_s}/public/”附加到self.image.url

于 2011-06-30T17:37:32.347 回答