This commit is contained in:
@@ -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
|
||||
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user