Skip to content

Instantly share code, notes, and snippets.

@yoones
Created March 12, 2019 21:50
Show Gist options
  • Save yoones/f5121f05915fe56e592fcc862adffc62 to your computer and use it in GitHub Desktop.
Save yoones/f5121f05915fe56e592fcc862adffc62 to your computer and use it in GitHub Desktop.
# Assuming a model defined like so:
class Post < ApplicationRecord
has_one_attached :image
end
# ...you can join against :image_attachment to select posts having attached images:
Post.joins(:image_attachment).where('published_at >= ?', Time.now)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment