Skip to content
Snippets Groups Projects
Commit 7c003207 authored by ArtOfCode-'s avatar ArtOfCode-
Browse files

Prevent loops

parent 0f04d08d
No related merge requests found
......@@ -15,8 +15,9 @@ $(() => {
const template = (tag) => {
const tagSpan = `<span>${tag.text}</span>`;
let desc = !!tag.desc ? splitWordsMaxLength(tag.desc, 120) : '';
const descSpan = !!tag.desc ?
`<br/><span class="has-color-tertiary-900 has-font-size-caption">${splitWordsMaxLength(tag.desc, 120)[0]}...</span>` :
`<br/><span class="has-color-tertiary-900 has-font-size-caption">${desc[0]}${desc.length > 1 ? '...' : ''}</span>` :
'';
return $(tagSpan + descSpan);
}
......
......@@ -8,6 +8,7 @@ class Tag < ApplicationRecord
validates :excerpt, length: { maximum: 600 }, allow_blank: true
validates :wiki_markdown, length: { maximum: 30000 }, allow_blank: true
validate :parent_not_own_child
def self.search(term)
where('name LIKE ?', "%#{sanitize_sql_like(term)}%")
......@@ -19,4 +20,13 @@ class Tag < ApplicationRecord
query = query.gsub('$ParentId', id.to_s)
ActiveRecord::Base.connection.execute(query).to_a.map(&:first)
end
private
def parent_not_own_child
return unless parent_id.present?
if all_children.include? parent_id
errors.add(:base, "The #{parent.name} tag is already a child of this tag.")
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment