Added adjusting ingredient amount
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user