みてるぞ 1 month ago
parent
commit
50a9313525
2 changed files with 13 additions and 27 deletions
  1. +3
    -17
      backend/app/controllers/tags_controller.rb
  2. +10
    -10
      backend/config/routes.rb

+ 3
- 17
backend/app/controllers/tags_controller.rb View File

@@ -1,14 +1,12 @@
class TagsController < ApplicationController class TagsController < ApplicationController
before_action :set_tags, only: %i[ show update destroy ]

def index def index
@tags =
tags =
if params[:post].present? if params[:post].present?
Tag.joins(:posts).where(posts: { id: params[:post] }) Tag.joins(:posts).where(posts: { id: params[:post] })
else else
Tag.all Tag.all
end end
render json: @tags
render json: tags
end end


def autocomplete def autocomplete
@@ -32,7 +30,7 @@ class TagsController < ApplicationController
end end


def show def show
render json: @tag
render json: Tag.find(params[:id])
end end


def create def create
@@ -43,16 +41,4 @@ class TagsController < ApplicationController


def destroy def destroy
end end

private

# Use callbacks to share common setup or constraints between actions.
def set_tag
@tag = Tag.find(params.expect(:id))
end

# Only allow a list of trusted parameters through.
def tag_params
params.expect(tag: [ :title, :body ])
end
end end

+ 10
- 10
backend/config/routes.rb View File

@@ -1,4 +1,14 @@
Rails.application.routes.draw do Rails.application.routes.draw do
get 'tags/autocomplete', to: 'tags#autocomplete'
post 'posts/:id/viewed', to: 'posts#viewed'
delete 'posts/:id/viewed', to: 'posts#unviewed'
get 'preview/title', to: 'preview#title'
get 'preview/thumbnail', to: 'preview#thumbnail'
get 'wiki/title/:title', to: 'wiki_pages#show_by_title'
get 'wiki/:id', to: 'wiki_pages#show'
post 'wiki', to: 'wiki_pages#create'
put 'wiki/:id', to: 'wiki_pages#update'

resources :posts resources :posts
resources :ip_addresses resources :ip_addresses
resources :nico_tag_relations resources :nico_tag_relations
@@ -15,16 +25,6 @@ Rails.application.routes.draw do
end end
end end


get 'tags/autocomplete', to: 'tags#autocomplete'
post 'posts/:id/viewed', to: 'posts#viewed'
delete 'posts/:id/viewed', to: 'posts#unviewed'
get 'preview/title', to: 'preview#title'
get 'preview/thumbnail', to: 'preview#thumbnail'
get 'wiki/title/:title', to: 'wiki_pages#show_by_title'
get 'wiki/:id', to: 'wiki_pages#show'
post 'wiki', to: 'wiki_pages#create'
put 'wiki/:id', to: 'wiki_pages#update'

# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html


# Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500. # Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.


Loading…
Cancel
Save