使用 ActiveStorage 时,如何在未附加文件时创建范围。
例如:
class Check < ActiveRecord::Base
has_one_attached :image
end
Run Code Online (Sandbox Code Playgroud)
我想要类似的东西Check.has_no_attached_image只返回没有现有附加图像的记录。
找到了附加图像但不是相反情况的答案
scope :has_attached_image, -> { joins(image_attachment: :blob) }