Skip to content

Commit

Permalink
Update controller
Browse files Browse the repository at this point in the history
Update views
  • Loading branch information
PabloBona committed Oct 12, 2023
1 parent 72211b9 commit 9757837
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
8 changes: 6 additions & 2 deletions app/controllers/general_shopping_lists_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class GeneralShoppingListsController < ApplicationController
def index
@recipes = Recipe.includes(:foods, :recipe_foods).all
@recipes = current_user.recipes.includes(:foods, :recipe_foods).all
@remaining_stock = calculate_remaining_stock(@recipes)
@total_quantity = calculate_total_quantity(@recipes)
@total_price = calculate_total_price(@recipes, @remaining_stock)
Expand Down Expand Up @@ -54,7 +54,11 @@ def calculate_remaining_stock(recipes)

required_quantity = recipe_food.quantity
available_quantity = food.quantity
remaining_stock[food.name] = required_quantity - available_quantity if available_quantity < required_quantity
remaining_stock[food.name] = if available_quantity < required_quantity
required_quantity - available_quantity
else
available_quantity - required_quantity
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/recipes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def create
private

def recipes_params
params.require(:recipe).permit(:name, :preparation_time, :cooking_time, :description)
params.require(:recipe).permit(:name, :preparation_time, :cooking_time, :description, :public)
end

def update_params
Expand Down
1 change: 1 addition & 0 deletions app/views/recipes/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<div class="d-flex flex-column align-items-center row-sm-2">
<%= form.label :description, "Description:", class: 'col-sm-7 col-md-7 col-lg-7 col-form-label' %>
<%= form.text_area :description, :required => true, class: 'col-sm-7 col-md-7 col-lg-7 form-control-lg rounded-3' %>
<%= form.hidden_field :public, value: false %>
</div>

<div class="d-flex column-gap-3 justify-content-center">
Expand Down

0 comments on commit 9757837

Please sign in to comment.