From da6a8f9d6c1833006bb8aa85a80a168357d316c9 Mon Sep 17 00:00:00 2001 From: maebeale Date: Sat, 7 Mar 2026 06:51:20 -0500 Subject: [PATCH] Make FAQs bookmarkable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add bookmark support to FAQs using the existing polymorphic bookmark pattern — association, SQL joins for title search/sort, bookmark icon in the FAQ accordion, and FAQ as a dropdown option on bookmark indexes. Co-Authored-By: Claude Opus 4.6 --- app/models/bookmark.rb | 7 +++++-- app/models/faq.rb | 2 ++ app/views/faqs/_faq.html.erb | 2 ++ spec/models/faq_spec.rb | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/models/bookmark.rb b/app/models/bookmark.rb index 9e6fe04f7..fa8b4da61 100644 --- a/app/models/bookmark.rb +++ b/app/models/bookmark.rb @@ -2,7 +2,7 @@ class Bookmark < ApplicationRecord belongs_to :user belongs_to :bookmarkable, polymorphic: true - BOOKMARKABLE_MODELS = %w[CommunityNews Event Organization Person Report Resource Story StoryIdea + BOOKMARKABLE_MODELS = %w[CommunityNews Event Faq Organization Person Report Resource Story StoryIdea Tutorial Workshop WorkshopIdea WorkshopLog WorkshopVariation WorkshopVariationIdea].freeze DROPDOWN_MODELS = (BOOKMARKABLE_MODELS - %w[Report]).freeze @@ -62,6 +62,7 @@ def self.sort_by_title bookmarks = self.joins(<<~SQL) LEFT JOIN community_news AS st_cn ON st_cn.id = bookmarks.bookmarkable_id AND bookmarks.bookmarkable_type = 'CommunityNews' LEFT JOIN events AS st_ev ON st_ev.id = bookmarks.bookmarkable_id AND bookmarks.bookmarkable_type = 'Event' + LEFT JOIN faqs AS st_faq ON st_faq.id = bookmarks.bookmarkable_id AND bookmarks.bookmarkable_type = 'Faq' LEFT JOIN organizations AS st_org ON st_org.id = bookmarks.bookmarkable_id AND bookmarks.bookmarkable_type = 'Organization' LEFT JOIN people AS st_ppl ON st_ppl.id = bookmarks.bookmarkable_id AND bookmarks.bookmarkable_type = 'Person' LEFT JOIN resources AS st_res ON st_res.id = bookmarks.bookmarkable_id AND bookmarks.bookmarkable_type = 'Resource' @@ -80,6 +81,7 @@ def self.sort_by_title COALESCE( st_cn.title, st_ev.title, + st_faq.question, CONCAT(st_ppl.first_name, ' ', st_ppl.last_name), st_org.name, st_rpt.type, @@ -106,6 +108,7 @@ def self.title(title) bookmarks = bookmarks.joins(<<~SQL) LEFT JOIN community_news ON community_news.id = bookmarks.bookmarkable_id AND bookmarks.bookmarkable_type = 'CommunityNews' LEFT JOIN events ON events.id = bookmarks.bookmarkable_id AND bookmarks.bookmarkable_type = 'Event' + LEFT JOIN faqs ON faqs.id = bookmarks.bookmarkable_id AND bookmarks.bookmarkable_type = 'Faq' LEFT JOIN organizations ON organizations.id = bookmarks.bookmarkable_id AND bookmarks.bookmarkable_type = 'Organization' LEFT JOIN people ON people.id = bookmarks.bookmarkable_id AND bookmarks.bookmarkable_type = 'Person' LEFT JOIN resources ON resources.id = bookmarks.bookmarkable_id AND bookmarks.bookmarkable_type = 'Resource' @@ -121,7 +124,7 @@ def self.title(title) SQL bookmarks.where( - "community_news.title LIKE :title OR events.title LIKE :title OR people.first_name LIKE :title OR + "community_news.title LIKE :title OR events.title LIKE :title OR faqs.question LIKE :title OR people.first_name LIKE :title OR people.last_name LIKE :title OR organizations.name LIKE :title OR resources.title LIKE :title OR reports.type LIKE :title OR stories.title LIKE :title OR workshops.title LIKE :title OR workshop_ideas.title LIKE :title OR diff --git a/app/models/faq.rb b/app/models/faq.rb index 0e144da06..077f9112a 100644 --- a/app/models/faq.rb +++ b/app/models/faq.rb @@ -2,6 +2,8 @@ class Faq < ApplicationRecord include Publishable positioned + has_many :bookmarks, as: :bookmarkable, dependent: :destroy + # Validations validates_presence_of :question, :answer diff --git a/app/views/faqs/_faq.html.erb b/app/views/faqs/_faq.html.erb index 5ef771d55..3608f72f7 100644 --- a/app/views/faqs/_faq.html.erb +++ b/app/views/faqs/_faq.html.erb @@ -100,6 +100,8 @@ <% end %> + <%= render "bookmarks/editable_bookmark_icon", resource: faq %> +