Moved adjust from IngredientsController to MealsController
This commit is contained in:
@@ -1,12 +1,5 @@
|
||||
class IngredientsController < ApplicationController
|
||||
include Concerns::Finders
|
||||
|
||||
before_action :find_ingredient, only: [:adjust]
|
||||
before_action :authorize
|
||||
|
||||
def adjust
|
||||
amount = params[:adjustment].to_i
|
||||
@ingredient.amount += amount if @ingredient.amount > -amount
|
||||
@ingredient.save
|
||||
end
|
||||
end
|
||||
|
||||
@@ -9,6 +9,7 @@ class MealsController < ApplicationController
|
||||
before_action :find_quantity_by_quantity_id, only: [:toggle_exposure]
|
||||
before_action :find_meal, only: [:edit, :update, :destroy, :edit_notes, :update_notes,
|
||||
:toggle_eaten]
|
||||
before_action :find_ingredient, only: [:adjust]
|
||||
before_action :authorize
|
||||
|
||||
def index
|
||||
@@ -65,6 +66,17 @@ class MealsController < ApplicationController
|
||||
prepare_meals
|
||||
end
|
||||
|
||||
def adjust
|
||||
amount = params[:adjustment].to_i
|
||||
@ingredient.amount += amount if @ingredient.amount > -amount
|
||||
@ingredient.save
|
||||
|
||||
prepare_meals
|
||||
@meal = @ingredient.composition
|
||||
@date = @meal.display_date
|
||||
@meal_index = @meals_by_date[@date].index(@meal)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def meal_params
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
$('tr[id=ingredient-<%= @ingredient.id %>] td.amount span')
|
||||
.html('<%= j "#{@ingredient.amount}" %>');
|
||||
9
app/views/meals/adjust.js.erb
Normal file
9
app/views/meals/adjust.js.erb
Normal file
@@ -0,0 +1,9 @@
|
||||
$('tr[id=ingredient-<%= @ingredient.id %>]').replaceWith(
|
||||
'<%= j render partial: 'meals/show_ingredient', locals: {i: @ingredient} %>'
|
||||
);
|
||||
$('tr[id=meal-<%= @meal.id %>]').replaceWith(
|
||||
'<%= j render partial: 'meals/show', locals: {m: @meal, index: @meal_index} %>'
|
||||
);
|
||||
$('tr[id=date-<%= @date.strftime('%Y%m%d') %>]').replaceWith(
|
||||
'<%= j render partial: 'meals/show_date', locals: {date: @date} %>'
|
||||
);
|
||||
Reference in New Issue
Block a user