Skip to content

Instantly share code, notes, and snippets.

@naveda89
Forked from fedesoria/paperclip_scopes.rb
Last active August 29, 2015 14:01
Show Gist options
  • Save naveda89/033ee723e43468ec7e78 to your computer and use it in GitHub Desktop.
Save naveda89/033ee723e43468ec7e78 to your computer and use it in GitHub Desktop.
# For finding images as in Article.attachments.images
scope :with_images, proc { |attachment| where('?_content_type LIKE ?', attachment, 'image%') }
# For finding other files Article.attachments.docs
scope :with_docs, proc { |attachment| where('?_content_type NOT LIKE ?', attachment, 'image%') }
@naveda89
Copy link
Author

naveda89 commented May 8, 2014

Scope now can receive the attachment type.

Usage: Model.with_images('avatar')
or Model.with_docs('manuals')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment