Skip to content

Commit

Permalink
Bug fix:Delete recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
RileyManda committed Oct 16, 2023
1 parent 4baf0af commit d1827d6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
7 changes: 7 additions & 0 deletions app/controllers/recipe_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion app/views/recipe/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
<p>Preparation Time: <%= recipe.preparation_time %> minutes</p>
<p>Cooking Time: <%= recipe.cooking_time %> minutes</p>
<p>Description: <%= recipe.description %></p>
<%= 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?" } %>

</li>
<% end %>
</ul>
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d1827d6

Please sign in to comment.