我正在将 pgsearch 添加到 Rails 6 Action Text 中,但不确定在 RichText 模型中包含 pgsearch 的最佳技术。我似乎无法在不破坏模型的情况下修补模型。我确实通过完全替换模型来让它工作,但显然不想那样做。任何想法如何使这项工作?这是我目前的模型:
include PgSearch
class ActionText::RichText < ActiveRecord::Base
self.table_name = "action_text_rich_texts"
multisearchable :against => :body
serialize :body, ActionText::Content
delegate :to_s, :nil?, to: :body
belongs_to :record, polymorphic: true, touch: true
has_many_attached :embeds
before_save do
self.embeds = body.attachments.map(&:attachable) if body.present?
end
def to_plain_text
body&.to_plain_text.to_s
end
delegate :blank?, :empty?, :present?, to: :to_plain_text
end
Run Code Online (Sandbox Code Playgroud)