はじまりの大地

This commit is contained in:
2025-02-25 22:43:13 +09:00
commit 5d64041c70
108 changed files with 20147 additions and 0 deletions
@@ -0,0 +1,2 @@
class ApplicationController < ActionController::API
end
@@ -0,0 +1,51 @@
class PostsController < ApplicationController
before_action :set_post, only: %i[ show update destroy ]
# GET /posts
def index
@posts = Post.all
render json: @posts
end
# GET /posts/1
def show
render json: @post
end
# POST /posts
def create
@post = Post.new(post_params)
if @post.save
render json: @post, status: :created, location: @post
else
render json: @post.errors, status: :unprocessable_entity
end
end
# PATCH/PUT /posts/1
def update
if @post.update(post_params)
render json: @post
else
render json: @post.errors, status: :unprocessable_entity
end
end
# DELETE /posts/1
def destroy
@post.destroy!
end
private
# Use callbacks to share common setup or constraints between actions.
def set_post
@post = Post.find(params.expect(:id))
end
# Only allow a list of trusted parameters through.
def post_params
params.expect(post: [ :title, :body ])
end
end