diff --git a/app/controllers/meals_controller.rb b/app/controllers/meals_controller.rb index a7de62d..34e8a5c 100644 --- a/app/controllers/meals_controller.rb +++ b/app/controllers/meals_controller.rb @@ -85,6 +85,9 @@ class MealsController < ApplicationController foods = @project.meal_foods.compute_quantities(@quantities) ingredients = @project.meal_ingredients + @amount_mfu_unit = ingredients + .each_with_object(Hash.new(0)) { |i, h| h[i.food.ref_unit] += 1 }.max_by(&:last).first + @nutrients = {} @quantities.each do |q| @nutrients[q] = ingredients.map do |i| diff --git a/app/views/meals/_index.html.erb b/app/views/meals/_index.html.erb index d3c2755..77d8e40 100644 --- a/app/views/meals/_index.html.erb +++ b/app/views/meals/_index.html.erb @@ -13,8 +13,8 @@

<%= date == Date.current ? 'Today' : date.strftime('%F') %>

- - <%= l(:field_amount) %> + + <%= l(:field_amount) %> <% @quantities.each do |q| %> + + <%= "[#{@amount_mfu_unit.shortname}]" %> + <% @quantities.each do |q| %> <% mfu_unit = @nutrients[q][:mfu_unit] %> - <%= "[#{ mfu_unit ? mfu_unit.shortname : '-'}]" %> + <%= "[#{mfu_unit ? mfu_unit.shortname : '-'}]" %> <% end %> diff --git a/app/views/meals/_show.html.erb b/app/views/meals/_show.html.erb index 8bcabe5..cc0351f 100644 --- a/app/views/meals/_show.html.erb +++ b/app/views/meals/_show.html.erb @@ -37,7 +37,8 @@ <%= i.food.name %> - <%= i.amount %>[<%= i.food.ref_unit.shortname %>] + <%= "%g" % i.amount %> + <%= "[#{i.food.ref_unit.shortname}]" unless i.food.ref_unit == @amount_mfu_unit %> <% @quantities.each do |q| %>