Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions app/models/bookmark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand All @@ -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,
Expand All @@ -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'
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions app/models/faq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ class Faq < ApplicationRecord
include Publishable
positioned

has_many :bookmarks, as: :bookmarkable, dependent: :destroy

# Validations
validates_presence_of :question, :answer

Expand Down
2 changes: 2 additions & 0 deletions app/views/faqs/_faq.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@
</div>
<% end %>

<%= render "bookmarks/editable_bookmark_icon", resource: faq %>

<button
type="button"
class="py-5 font-medium text-left cursor-pointer"
Expand Down
2 changes: 1 addition & 1 deletion spec/models/faq_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# let(:faq) { build(:faq) } # Keep if needed

describe "associations" do
# Add association tests if any
it { should have_many(:bookmarks).dependent(:destroy) }
end

describe "validations" do
Expand Down