parsley/app/controllers/task_lists_controller.rb

52 lines
1.1 KiB
Ruby
Raw Normal View History

2018-08-27 17:46:33 -05:00
class TaskListsController < ApplicationController
before_action :ensure_valid_user
before_action :set_task_list, only: [:show, :update, :destroy]
def index
2018-09-05 11:00:35 -05:00
@task_lists = TaskList.for_user(current_user).order(created_at: :desc)
2018-08-27 17:46:33 -05:00
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