app/models/meal/form_object.rb
# custom behaviour of the Meal::FormObject
custom behaviour of the Meal::FormObject
custom behaviour of the Meal :: FormObject
def assign_attributes(new_attributes)
      extract_ingredients_action_args(new_attributes)
      if ingredient_action == :delete
        new_attributes[:ingredients_attributes][ingredient_index.to_s][:_destroy] = '1'
      end
      if (new_attributes.dig(:ingredients_attributes, ingredient_index.to_s)||{}).delete(:save_as_nutrient) == '1'
        Nutrient.create(new_attributes[:ingredients_attributes][ingredient_index.to_s].select do |k, _|
          (Nutrient.float_keys.map{ |k| "#{k}_integral" } + Nutrient.float_keys.map{ |k| "#{k}_fractional" } + ['name']).include?(k)
        end)
      end
      @meal.assign_attributes(new_attributes)
    end
def assign_attributes ( new_attributes ) extract_ingredients_action_args ( new_attributes ) if ingredient_action == :delete new_attributes [ :ingredients_attributes ] [ ingredient_index . to_s ] [ :_destroy ] = '1' end if ( new_attributes . dig ( :ingredients_attributes , ingredient_index . to_s ) || { } ) . delete ( :save_as_nutrient ) == '1' Nutrient . create ( new_attributes [ :ingredients_attributes ] [ ingredient_index . to_s ] . select do | k , _ | ( Nutrient . float_keys . map { | k | "#{k}_integral" } + Nutrient . float_keys . map { | k | "#{k}_fractional" } + [ 'name' ] ) . include? ( k ) end ) end @meal . assign_attributes ( new_attributes ) end
custom behaviour of the Meal::FormObject
custom behaviour of the Meal :: FormObject
new_attributes
<not_specific>