PostgreSQL检查Paperclip附件是否存在

时间:2014-09-02 17:04:37

标签: sql ruby-on-rails postgresql

我试图遍历我的产品postgres表,然后显示附加了Paperclip图像的前5个,但我的查询都没有工作。在我的产品模型中,Paperclip附件被称为photo_image_file,photo_file_name,photo_content_type等。

这是代码行:

<% featured = Product.order('created_at DESC').limit(5).where("photo_file_name?") %>

要完成此任务的正确PostgreSQL查询是什么?它只需要返回一个真正的布尔值。

1 个答案:

答案 0 :(得分:0)

尝试以下方法:

Product.where.not(photo_file_name: nil).limit(5).order(created_at: :desc)