Skip to content

Instantly share code, notes, and snippets.

@youliangdao
Created December 3, 2022 00:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save youliangdao/3fa64e8d357789d80db9f7f8171487be to your computer and use it in GitHub Desktop.
Save youliangdao/3fa64e8d357789d80db9f7f8171487be to your computer and use it in GitHub Desktop.
class TasksController < ApplicationController
before_action :set_task, only: %i[ update destroy ]
# GET /tasks
def index
@tasks = Task.all
end
# POST /tasks
def create
@task = Task.new(task_params)
if @task.save
render json: Task.all, status: :created
else
render status: :unprocessable_entity
end
end
# PATCH/PUT /tasks/1
def update
if @task.update(task_params)
render json: Task.all, status: :ok
else
render status: :unprocessable_entity
end
end
# DELETE /tasks/1
def destroy
@task.destroy
render json: Task.all, status: :ok
end
private
def set_task
@task = Task.find(params[:id])
end
def task_params
params.require(:task).permit(:title, :checked)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment