Added adjusting ingredient amount
This commit is contained in:
parent
03d0a56474
commit
66cd7926e8
@ -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
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
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%;">
|
<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 " #{i.amount} " } %>
|
<%= adjust_ingredient_links(i) { raw " <span>#{i.amount}</span> " } %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
Reference in New Issue
Block a user