From 64735b5ee5d7cb0a99579d0a46e8750123beded8 Mon Sep 17 00:00:00 2001 From: Dan Elbert Date: Sun, 9 May 2021 23:31:44 -0500 Subject: [PATCH] Convert recipe to task list --- app/controllers/task_lists_controller.rb | 12 ++++++++- app/javascript/components/RecipeShow.vue | 34 ++++++++++++++++++++++++ app/javascript/lib/Api.js | 4 +++ app/javascript/store/index.js | 8 ++++++ app/models/task_list.rb | 22 +++++++++++++++ app/views/home/index.html.erb | 2 +- config/routes.rb | 3 +++ 7 files changed, 83 insertions(+), 2 deletions(-) diff --git a/app/controllers/task_lists_controller.rb b/app/controllers/task_lists_controller.rb index b321401..a48e1e8 100644 --- a/app/controllers/task_lists_controller.rb +++ b/app/controllers/task_lists_controller.rb @@ -1,7 +1,7 @@ class TaskListsController < ApplicationController before_action :ensure_valid_user - before_action :set_task_list, only: [:show, :update, :destroy] + before_action :set_task_list, only: [:show, :update, :destroy, :add_recipe] def index @task_lists = TaskList.for_user(current_user).includes(:task_items).order(created_at: :desc) @@ -40,6 +40,16 @@ class TaskListsController < ApplicationController head :no_content end end + + def add_recipe + ensure_owner(@task_list) do + recipe = Recipe.find(params[:recipe_id]) + + @task_list.add_recipe_ingredients(recipe) + + head :no_content + end + end private diff --git a/app/javascript/components/RecipeShow.vue b/app/javascript/components/RecipeShow.vue index c249bf9..5065b47 100644 --- a/app/javascript/components/RecipeShow.vue +++ b/app/javascript/components/RecipeShow.vue @@ -37,6 +37,11 @@
Ingredients + + +