このコミットが含まれているのは:
2025-05-23 01:02:12 +09:00
コミット db430cc426
7個のファイルの変更158行の追加8行の削除
+17 -3
ファイルの表示
@@ -3,14 +3,28 @@ class PostsController < ApplicationController
# GET /posts
def index
@posts = Post.all
if params[:tags].present?
tag_names = params[:tags].split(',')
match_type = params[:match]
if match_type == 'any'
@posts = Post.joins(:tags).where(tags: { name: tag_names }).distinct
else
@posts = Post.joins(:tags)
tag_names.each do |tag|
@posts = @posts.where(id: Post.joins(:tags).where(tags: { name: tag }))
end
@posts = @posts.distinct
end
else
@posts = Post.all
end
render json: @posts
end
# GET /posts/1
def show
render json: @post
@post = Post.includes(:tags).find(params[:id])
render json: @post.as_json(include: { tags: { only: [:id, :name] } })
end
# POST /posts