parsley/app/controllers/task_lists_controller.rb
Dan Elbert 18603dc783
Some checks failed
parsley/pipeline/head There was a failure building this commit
tasks
2018-09-06 18:16:13 -05:00

52 lines
1.1 KiB
Ruby

class TaskListsController < ApplicationController
before_action :ensure_valid_user
before_action :set_task_list, only: [:show, :update, :destroy]
def index
@task_lists = TaskList.for_user(current_user).includes(:task_items).order(created_at: :desc)
end
def show
ensure_owner(@task_list)
end
def create
@task_list = TaskList.new(task_list_params)
@task_list.user = current_user
if @task_list.save
render :show, status: :created, location: @task_list
else
render json: @task_list.errors, status: :unprocessable_entity
end
end
def update
ensure_owner(@task_list) do
if @task_list.update(task_list_params)
render :show, status: :ok, location: @task_list
else
render json: @task_list.errors, status: :unprocessable_entity
end
end
end
def destroy
ensure_owner(@task_list) do
@task_list.destroy
head :no_content
end
end
private
def task_list_params
params.require(:task_list).permit(:name)
end
def set_task_list
@task_list = TaskList.find(params[:id])
end
end