diff --git a/app/controllers/ingredients_controller.rb b/app/controllers/ingredients_controller.rb index 9834e5d..eadc642 100644 --- a/app/controllers/ingredients_controller.rb +++ b/app/controllers/ingredients_controller.rb @@ -19,21 +19,20 @@ class IngredientsController < ApplicationController @ingredient.nutrients.new(ingredient: @ingredient) ingredients = @project.ingredients.includes(:ref_unit, nutrients: [:quantity, :unit]) - @header = @project.quantities.where(primary: true) - @nutrients = {} - @descriptions = {} + @primary_quantities = @project.quantities.where(primary: true) + @primary_nutrients = {} + @extra_nutrients = {} ingredients.each do |i| - @nutrients[i] = {} - @descriptions[i] = [] + @primary_nutrients[i] = {} + @extra_nutrients[i] = {} i.nutrients.sort_by { |n| n.quantity.lft }.each do |n| - if @header.include?(n.quantity) - @nutrients[i][n.quantity_id] = "#{n.amount} [#{n.unit.shortname}]" + if @primary_quantities.include?(n.quantity) + @primary_nutrients[i][n.quantity_id] = "#{n.amount} [#{n.unit.shortname}]" else - @descriptions[i] << "#{n.quantity.name}: #{n.amount} [#{n.unit.shortname}]" + @extra_nutrients[i][n.quantity.name] = "#{n.amount} [#{n.unit.shortname}]" end end end - @descriptions.each { |i, v| @descriptions[i] = v.join(", ") } end def create diff --git a/app/views/ingredients/nutrients.html.erb b/app/views/ingredients/nutrients.html.erb index 3f3dbf5..3832307 100644 --- a/app/views/ingredients/nutrients.html.erb +++ b/app/views/ingredients/nutrients.html.erb @@ -13,38 +13,54 @@ <%= render :partial => 'ingredients/form' %>
<%= l(:field_name) %> | - <% @header.each do |q| %> -<%= q.name %> | +<%= l(:field_name) %> | + <% @primary_quantities.each do |q| %> +<%= q.name %> | <% end %>
---|---|---|---|
<%= link_to '', '#', { - onclick: "$(this).closest('tr').next('tr').toggle(); $(this).toggleClass('icon-bullet-closed'); $(this).toggleClass('icon-bullet-open'); return false;", + onclick: "$(this).closest('tr').nextUntil('tr.primary', 'tr').toggle(); $(this).toggleClass('icon-bullet-closed'); $(this).toggleClass('icon-bullet-open'); return false;", class: "icon icon-bullet-closed" } %> <%= i.name %> | - <% @header.each do |q| %> -<%= values[q.id] || '-' %> | + <% @primary_quantities.each do |q| %> ++ <%= values[q.id] || '-' %> + | <% end %>