检查载波图像版本是否存在



使用Carrierwave和Fog将图像上传到S3,我想检查图像版本是否存在。

我正在使用此代码(受此答案的启发)来检查它是否存在

- if post.image_url(:thumb).file.exists?
  .media-cover{:style => "background-image: url(#{post.image_url(:thumb)}"}

但是我收到此错误

NoMethodError at /
undefined method `file' for #<String:0x007fb7ab7af980>

我可以使用post.image_url访问默认版本

很明显,

它返回的是 :thumb image_url而不是版本本身,因此您无法获取文件。您可以通过以下方式查看:

post.thumb.file.exists?

拇指文件是否存在,则使用 URL 帮助程序

最新更新