diff --git a/app/controllers/recipe_controller.rb b/app/controllers/recipe_controller.rb index 85e8b96..fdc21b0 100644 --- a/app/controllers/recipe_controller.rb +++ b/app/controllers/recipe_controller.rb @@ -6,4 +6,11 @@ def index def recipe_params params.require(:recipe).permit(:name, :preparation_time, :cooking_time, :description, :public, :user_id) end + + def destroy + @recipe = Recipe.find(params[:id]) + @recipe.destroy + redirect_to recipe_path, notice: "Recipe was successfully deleted." +end + end diff --git a/app/views/recipe/index.html.erb b/app/views/recipe/index.html.erb index 4d2374b..91c5cab 100644 --- a/app/views/recipe/index.html.erb +++ b/app/views/recipe/index.html.erb @@ -6,7 +6,8 @@
Preparation Time: <%= recipe.preparation_time %> minutes
Cooking Time: <%= recipe.cooking_time %> minutes
Description: <%= recipe.description %>
- <%= button_to "Remove", remove_recipe_path(recipe), method: :delete, data: { confirm: "Are you sure?" } %> + <%= button_to "Remove", recipe, method: :delete, data: { confirm: "Are you sure?" } %> + <% end %> diff --git a/config/routes.rb b/config/routes.rb index 97cdbb7..a691522 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -7,5 +7,5 @@ delete 'recipes/:id', to: 'recipes#destroy', as: 'remove_recipe' resources :users, only: [:index, :show, :new, :create] resources :recipe_food, only: [:index, :new, :create] - resources :recipe, only: [:index, :new, :create] + resources :recipe, only: [:index, :new, :create, :destroy] end \ No newline at end of file