1
0

Added adjusting ingredient amount

This commit is contained in:
cryptogopher
2020-04-19 21:50:59 +02:00
parent 03d0a56474
commit 66cd7926e8
5 changed files with 15 additions and 7 deletions

View File

@@ -8,6 +8,13 @@ module Concerns::Finders
render_404
end
def find_ingredient
@ingredient = Ingredient.find(params[:id])
@project = @ingredient.composition.project
rescue ActiveRecord::RecordNotFound
render_404
end
def find_food
@food = Food.find(params[:id])
@project = @food.project

View File

@@ -5,6 +5,8 @@ class IngredientsController < ApplicationController
before_action :authorize
def adjust
params.require(:ingredient).permit(:adjustment)
amount = params[:adjustment].to_i
@ingredient.amount += amount if @ingredient.amount > -amount
@ingredient.save
end
end

View File

@@ -40,14 +40,11 @@ class MealsController < ApplicationController
end
def update_notes
if @meal.update(params.require(:meal).permit(:notes))
flash[:notice] = 'Updated meal notes' unless @meal.previous_changes.empty?
end
@meal.update(params.require(:meal).permit(:notes))
end
def toggle_eaten
@meal.toggle_eaten!
flash[:notice] = 'Updated meal status'
prepare_meals
end