Add tags in edit endpoint

This commit is contained in:
2023-02-03 11:45:02 +11:00
parent 548dd1cbee
commit 2ff8f0a32f
2 changed files with 19 additions and 1 deletions

View File

@@ -27,6 +27,24 @@ module Adamantium
end
end
def tag_post(post_id:, tags:)
tags.each do |tag_name|
next if tag_name == ""
tag = post.tags.where(label: tag_name).one ||
post
.tags
.changeset(:create, {label: tag_name, slug: tag_name.downcase.strip.tr(" ", "-").gsub(/[^\w-]/, "")})
.commit
posts.post_tags.changeset(:create, {
post_id: post_id,
tag_id: tag[:id]
})
.commit
end
end
def post_listing(limit: nil)
posts
.where(post_type: "post")