-
-
Save youliangdao/3fa64e8d357789d80db9f7f8171487be to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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