From 50a9313525c7491d08fc522eeeb5a033da7ce43a Mon Sep 17 00:00:00 2001 From: miteruzo Date: Sun, 15 Jun 2025 00:41:27 +0900 Subject: [PATCH] #42 --- backend/app/controllers/tags_controller.rb | 20 +++----------------- backend/config/routes.rb | 20 ++++++++++---------- 2 files changed, 13 insertions(+), 27 deletions(-) diff --git a/backend/app/controllers/tags_controller.rb b/backend/app/controllers/tags_controller.rb index ee4fade..fb967c5 100644 --- a/backend/app/controllers/tags_controller.rb +++ b/backend/app/controllers/tags_controller.rb @@ -1,14 +1,12 @@ class TagsController < ApplicationController - before_action :set_tags, only: %i[ show update destroy ] - def index - @tags = + tags = if params[:post].present? Tag.joins(:posts).where(posts: { id: params[:post] }) else Tag.all end - render json: @tags + render json: tags end def autocomplete @@ -32,7 +30,7 @@ class TagsController < ApplicationController end def show - render json: @tag + render json: Tag.find(params[:id]) end def create @@ -43,16 +41,4 @@ class TagsController < ApplicationController def destroy 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 diff --git a/backend/config/routes.rb b/backend/config/routes.rb index d57426e..2495357 100644 --- a/backend/config/routes.rb +++ b/backend/config/routes.rb @@ -1,4 +1,14 @@ 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 :ip_addresses resources :nico_tag_relations @@ -15,16 +25,6 @@ Rails.application.routes.draw do 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 # Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.