Files
manyfold/app/models/concerns/linkable.rb
James Smith 6f55216dd3 Ignore all links to the local hostname
If we do need to link between models, we will do it with proper relationships.
2025-10-15 15:49:24 +01:00

15 lines
502 B
Ruby

module Linkable
extend ActiveSupport::Concern
included do
has_many :links, as: :linkable, dependent: :destroy
accepts_nested_attributes_for :links, reject_if: :link_not_valid?, allow_destroy: true
scope :linked_to, ->(url) { includes(:links).where("links.url": url) }
def link_not_valid?(attributes)
attributes[:url].blank? || links.map(&:url).include?(attributes[:url]) || [PublicUrl.hostname, "localhost"].include?(URI.parse(attributes[:url]).hostname)
end
end
end