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 render_404
end end
def find_ingredient
@ingredient = Ingredient.find(params[:id])
@project = @ingredient.composition.project
rescue ActiveRecord::RecordNotFound
render_404
end
def find_food def find_food
@food = Food.find(params[:id]) @food = Food.find(params[:id])
@project = @food.project @project = @food.project

View File

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

View File

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

View File

@ -0,0 +1,2 @@
$('tr[id=ingredient-<%= @ingredient.id %>] td.amount span')
.html('<%= j "#{@ingredient.amount}" %>');

View File

@ -21,8 +21,8 @@
<td class="name unwrappable" style="width: 5%;"> <td class="name unwrappable" style="width: 5%;">
<%= i.food.name %> <%= i.food.name %>
</td> </td>
<td style="text-align: left;" class="unwrappable" colspan="2"> <td class="amount unwrappable" style="text-align: left;" colspan="2">
<%= adjust_ingredient_links(i) { raw "&emsp;#{i.amount}&emsp;" } %> <%= adjust_ingredient_links(i) { raw "&emsp;<span>#{i.amount}</span>&emsp;" } %>
</td> </td>
</tr> </tr>
<% end %> <% end %>