From 30726ec1b8cca20b232a6f246faaae2a6ad6eb89 Mon Sep 17 00:00:00 2001 From: Dan Elbert Date: Tue, 5 Jul 2016 11:19:18 -0500 Subject: [PATCH] update ingredient list --- app/decorators/ingredient_decorator.rb | 17 +++++++++++++++++ app/views/ingredients/index.html.erb | 10 +++++----- 2 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 app/decorators/ingredient_decorator.rb diff --git a/app/decorators/ingredient_decorator.rb b/app/decorators/ingredient_decorator.rb new file mode 100644 index 0000000..de2c491 --- /dev/null +++ b/app/decorators/ingredient_decorator.rb @@ -0,0 +1,17 @@ +class IngredientDecorator < BaseDecorator + + def ndbn_check + if ndbn.present? + "".html_safe + else + '' + end + end + + def density + if wrapped.density.present? + value = UnitConversion::parse(wrapped.density) + value.convert('oz/cup').change_formatter(UnitConversion::DecimalFormatter.new).pretty_value + end + end +end \ No newline at end of file diff --git a/app/views/ingredients/index.html.erb b/app/views/ingredients/index.html.erb index 5d0f8b6..cc34471 100644 --- a/app/views/ingredients/index.html.erb +++ b/app/views/ingredients/index.html.erb @@ -16,22 +16,22 @@ Name - USDA NDBN + USDA KCal per 100g - Density + Density (oz/cup) - <% @ingredients.each do |ingredient| %> + <% decorate(@ingredients, IngredientDecorator).each do |ingredient| %> <%= link_to ingredient.name, edit_ingredient_path(ingredient) %> - <%= ingredient.ndbn %> + <%= ingredient.ndbn_check %> <%= ingredient.kcal %> <%= ingredient.density %> - <%= link_to ingredient, method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-sm btn-danger' do %> + <%= link_to ingredient, method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-xs btn-danger' do %> <% end %>