1
0

Flashing through #now on AJAX actions

This commit is contained in:
cryptogopher 2020-09-05 21:56:05 +02:00
parent 14285b510c
commit 2a8f60be36
5 changed files with 14 additions and 13 deletions

View File

@ -26,7 +26,7 @@ class FoodsController < ApplicationController
def create def create
@food = @project.foods.new(food_params) @food = @project.foods.new(food_params)
if @food.save if @food.save
flash[:notice] = 'Created new food' flash.now[:notice] = 'Created new food'
prepare_items prepare_items
else else
@food.nutrients.new(unit: @food.ref_unit) if @food.nutrients.empty? @food.nutrients.new(unit: @food.ref_unit) if @food.nutrients.empty?
@ -39,7 +39,7 @@ class FoodsController < ApplicationController
def update def update
if @food.update(food_params) if @food.update(food_params)
flash[:notice] = 'Updated food' flash.now[:notice] = 'Updated food'
prepare_items prepare_items
render :index render :index
else else

View File

@ -24,7 +24,7 @@ class MealsController < ApplicationController
def create def create
@meal = @project.meals.new(meal_params) @meal = @project.meals.new(meal_params)
if @meal.save if @meal.save
flash[:notice] = 'Created new meal' flash.now[:notice] = 'Created new meal'
prepare_meals prepare_meals
else else
@meal.ingredients.new if @meal.ingredients.empty? @meal.ingredients.new if @meal.ingredients.empty?
@ -37,7 +37,7 @@ class MealsController < ApplicationController
def update def update
if @meal.update(meal_params) if @meal.update(meal_params)
flash[:notice] = 'Updated meal' flash.now[:notice] = 'Updated meal'
prepare_meals prepare_meals
render :index render :index
else else
@ -46,7 +46,7 @@ class MealsController < ApplicationController
end end
def destroy def destroy
flash[:notice] = 'Deleted meal' if @meal.destroy flash.now[:notice] = 'Deleted meal' if @meal.destroy
end end
def edit_notes def edit_notes

View File

@ -42,7 +42,7 @@ class MeasurementsController < ApplicationController
routine.quantities << @measurement.readouts.map(&:quantity).first(6) routine.quantities << @measurement.readouts.map(&:quantity).first(6)
end end
flash[:notice] = 'Created new measurement' flash.now[:notice] = 'Created new measurement'
prepare_items prepare_items
else else
@measurement.readouts.new if @measurement.readouts.empty? @measurement.readouts.new if @measurement.readouts.empty?
@ -56,10 +56,11 @@ class MeasurementsController < ApplicationController
def update def update
update_routine_from_params update_routine_from_params
if @measurement.update(measurement_params) if @measurement.update(measurement_params)
flash[:notice] = 'Updated measurement'
if @measurement.routine.previous_changes.has_key?(:name) && @routine if @measurement.routine.previous_changes.has_key?(:name) && @routine
flash[:notice] = 'Updated measurement'
render js: "window.location.pathname='#{readouts_measurement_routine_path(@routine)}'" render js: "window.location.pathname='#{readouts_measurement_routine_path(@routine)}'"
else else
flash.now[:notice] = 'Updated measurement'
prepare_items prepare_items
render :index render :index
end end
@ -70,7 +71,7 @@ class MeasurementsController < ApplicationController
def destroy def destroy
if @measurement.destroy if @measurement.destroy
flash[:notice] = 'Deleted measurement' flash.now[:notice] = 'Deleted measurement'
end end
end end

View File

@ -24,7 +24,7 @@ class QuantitiesController < ApplicationController
def create def create
@quantity = @project.quantities.new(quantity_params) @quantity = @project.quantities.new(quantity_params)
if @quantity.save if @quantity.save
flash[:notice] = 'Created new quantity' flash.now[:notice] = 'Created new quantity'
prepare_quantities prepare_quantities
else else
render :new render :new
@ -37,7 +37,7 @@ class QuantitiesController < ApplicationController
def update def update
if @quantity.update(quantity_params) if @quantity.update(quantity_params)
flash[:notice] = 'Updated quantity' flash.now[:notice] = 'Updated quantity'
prepare_quantities prepare_quantities
render :index render :index
else else
@ -48,7 +48,7 @@ class QuantitiesController < ApplicationController
def destroy def destroy
@quantity_tree = @quantity.self_and_descendants.load @quantity_tree = @quantity.self_and_descendants.load
if @quantity.destroy if @quantity.destroy
flash[:notice] = 'Deleted quantity' flash.now[:notice] = 'Deleted quantity'
end end
end end
@ -95,7 +95,7 @@ class QuantitiesController < ApplicationController
@parent_quantity = @quantity.parent @parent_quantity = @quantity.parent
render :new_child render :new_child
end end
flash[:notice] = 'Created new quantity' flash.now[:notice] = 'Created new quantity'
prepare_quantities prepare_quantities
end end

View File

@ -37,7 +37,7 @@ class TargetsController < ApplicationController
# :save only after build, to re-display values in case records are invalid # :save only after build, to re-display values in case records are invalid
if @goal.save && Target.transaction { @targets.all?(&:save) } if @goal.save && Target.transaction { @targets.all?(&:save) }
flash[:notice] = 'Created new target(s)' flash.now[:notice] = 'Created new target(s)'
# create view should only refresh targets belonging to @goal # create view should only refresh targets belonging to @goal
# e.g. by rendering to div#goal-id-targets # e.g. by rendering to div#goal-id-targets
prepare_targets prepare_targets