Added adjusting ingredient amount
This commit is contained in:
parent
03d0a56474
commit
66cd7926e8
@ -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
|
||||
|
||||
|
2
app/views/ingredients/adjust.js.erb
Normal file
2
app/views/ingredients/adjust.js.erb
Normal file
@ -0,0 +1,2 @@
|
||||
$('tr[id=ingredient-<%= @ingredient.id %>] td.amount span')
|
||||
.html('<%= j "#{@ingredient.amount}" %>');
|
@ -21,8 +21,8 @@
|
||||
<td class="name unwrappable" style="width: 5%;">
|
||||
<%= i.food.name %>
|
||||
</td>
|
||||
<td style="text-align: left;" class="unwrappable" colspan="2">
|
||||
<%= adjust_ingredient_links(i) { raw " #{i.amount} " } %>
|
||||
<td class="amount unwrappable" style="text-align: left;" colspan="2">
|
||||
<%= adjust_ingredient_links(i) { raw " <span>#{i.amount}</span> " } %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
Reference in New Issue
Block a user