summaryrefslogtreecommitdiff
path: root/app/helpers/recipes_helper.rb
diff options
context:
space:
mode:
authorMarius Peter <marius.peter@tutanota.com>2025-08-24 20:29:54 +0200
committerMarius Peter <marius.peter@tutanota.com>2025-08-24 20:29:54 +0200
commit52b044d6a4278c229992404ad5801769c2d13363 (patch)
treeb30b34da58f26117c035391d09366b190350b1e3 /app/helpers/recipes_helper.rb
First commit.
Vive le Castel Peter !
Diffstat (limited to 'app/helpers/recipes_helper.rb')
-rw-r--r--app/helpers/recipes_helper.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/app/helpers/recipes_helper.rb b/app/helpers/recipes_helper.rb
new file mode 100644
index 0000000..02cb1a7
--- /dev/null
+++ b/app/helpers/recipes_helper.rb
@@ -0,0 +1,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