This commit is contained in:
2025-12-19 01:37:08 +09:00
parent 7ba814b5f9
commit fb9e708261
3 changed files with 103 additions and 89 deletions
@@ -0,0 +1,27 @@
class TagChildrenController < ApplicationController
def create
return head :unauthorized unless current_user
return head :forbidden unless current_user.admin?
parent_id = params[:parent_id]
child_id = params[:child_id]
return head :bad_request if parent_id.blank? || child_id.blank?
Tag.find(parent_id).children << Tag.find(child_id) rescue nil
head :no_content
end
def destroy
return head :unauthorized unless current_user
return head :forbidden unless current_user.admin?
parent_id = params[:parent_id]
child_id = params[:child_id]
return head :bad_request if parent_id.blank? || child_id.blank?
Tag.find(parent_id).children.delete(Tag.find(child_id)) rescue nil
head :no_content
end
end
+2
View File
@@ -3,6 +3,8 @@ Rails.application.routes.draw do
put 'tags/nico/:id', to: 'nico_tags#update'
get 'tags/autocomplete', to: 'tags#autocomplete'
get 'tags/name/:name', to: 'tags#show_by_name'
post 'tags/:parent_id/children/:child_id', to: 'tag_children#create'
delete 'tags/:parent_id/children/:child_id', to: 'tag_children#destroy'
get 'posts/random', to: 'posts#random'
get 'posts/changes', to: 'posts#changes'
post 'posts/:id/viewed', to: 'posts#viewed'