require_dependency "todo_rails/application_controller" module TodoRails class TasksController < ApplicationController before_action :set_task, only: [:show, :edit, :update, :destroy] # GET /tasks def index @tasks = Task.all render json: @tasks end # GET /tasks/1 def show render json: @task end # POST /tasks def create @task = Task.new(task_params) if @task.save render json: @task, status: :created, location: @task else render json: @task.errors, status: :unprocessable_entity end end # PATCH/PUT /tasks/1 def update if @task.update(task_params) head :no_content else render json: @task.errors, status: :unprocessable_entity end end # DELETE /tasks/1 def destroy @task.destroy head :no_content end private # Use callbacks to share common setup or constraints between actions. def set_task @task = Task.find(params[:id]) end # Only allow a trusted parameter "white list" through. def task_params params.require(:task).permit(:title, :completed, :row_order, :priority, :comment) end end end