diff options
author | Marius Peter <marius.peter@tutanota.com> | 2025-08-24 20:29:54 +0200 |
---|---|---|
committer | Marius Peter <marius.peter@tutanota.com> | 2025-08-24 20:29:54 +0200 |
commit | 52b044d6a4278c229992404ad5801769c2d13363 (patch) | |
tree | b30b34da58f26117c035391d09366b190350b1e3 /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.rb | 16 |
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 |