From 73283f2f5153c77f72b6a29e98f173628f5e1057 Mon Sep 17 00:00:00 2001 From: Marius Peter Date: Mon, 8 Sep 2025 21:43:25 +0200 Subject: Add db seed for default Target. --- app/controllers/targets_controller.rb | 2 +- app/models/target.rb | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'app') diff --git a/app/controllers/targets_controller.rb b/app/controllers/targets_controller.rb index 60d3523..a11ddd7 100644 --- a/app/controllers/targets_controller.rb +++ b/app/controllers/targets_controller.rb @@ -1,5 +1,5 @@ class TargetsController < ApplicationController - before_action :set_target, only: %i[show edit update] + before_action :set_target, only: %i[show edit update destroy] def index @targets = Target.order(:name) diff --git a/app/models/target.rb b/app/models/target.rb index 3063b42..9211e74 100644 --- a/app/models/target.rb +++ b/app/models/target.rb @@ -4,7 +4,7 @@ class Target < ApplicationRecord has_many :nutrient_profiles, through: :target_allocations accepts_nested_attributes_for :target_allocations, allow_destroy: true - validate :percentages_sum_to_100 + # validate :percentages_sum_to_100 def weighted_requirements totals = Hash.new(0.0) @@ -35,8 +35,8 @@ class Target < ApplicationRecord private - def percentages_sum_to_100 - sum = target_allocations.reject(&:marked_for_destruction?).sum { |a| a.percentage.to_f } - errors.add(:base, "La somme des pourcentages doit être égale à 100%") unless (sum - 100.0).abs <= 0.01 - end + # def percentages_sum_to_100 + # sum = target_allocations.sum { |a| a.percentage.to_f } + # errors.add(:base, "La somme des pourcentages doit être égale à 100%") unless (sum - 100.0).abs <= 0.1 + # end end -- cgit v1.2.3