From 40a292238b0469612d9cee291d447a150b692f9c Mon Sep 17 00:00:00 2001 From: Peter Hankiewicz Date: Tue, 3 Jan 2023 13:55:48 +0100 Subject: [PATCH] Add new scope to notices to filter out notices with attachments --- app/models/notice.rb | 1 + config/initializers/rails_admin.rb | 2 ++ 2 files changed, 3 insertions(+) diff --git a/app/models/notice.rb b/app/models/notice.rb index b97e4b68..7b9a2035 100644 --- a/app/models/notice.rb +++ b/app/models/notice.rb @@ -124,6 +124,7 @@ class Notice < ApplicationRecord # == Scopes =============================================================== scope :top_notices_token_urls, -> { joins(:archived_token_urls).select('notices.*, COUNT(archived_token_urls.id) AS counted_archived_token_urls').group('notices.id') } + scope :with_attachments, -> { includes(:file_uploads).where.not(file_uploads: { id: nil }) } # == Aliases ============================================================== alias_attribute :tags, :tag_list diff --git a/config/initializers/rails_admin.rb b/config/initializers/rails_admin.rb index a1d5d1e1..6c9c69a0 100644 --- a/config/initializers/rails_admin.rb +++ b/config/initializers/rails_admin.rb @@ -74,6 +74,8 @@ # avoid calling it. limited_pagination true + scopes [nil, :with_attachments] + field :id field :title field(:date_sent) { label 'Sent' }