summaryrefslogtreecommitdiff
path: root/app/helpers/recipes_helper.rb
blob: 02cb1a79695e02649d586e6993b9d445aa8f9799 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
module RecipesHelper
  def commercial_name_for(component)
    # Try to find a FertilizerProduct via a join, but gracefully fallback.
    if defined?(FertilizerProduct) && defined?(FertilizerComposition)
      prod = FertilizerProduct.joins(:fertilizer_compositions)
               .where(fertilizer_compositions: { fertilizer_component_id: component.id })
               .first
      return prod.name if prod&.name.present?
    end
    component.name.presence || component.formula
  end

  def fmt_kg(v)
    number_with_precision(v.to_f, precision: 2, strip_insignificant_zeros: true)
  end
end
Copyright 2019--2025 Marius PETER