update ingredient list

This commit is contained in:
Dan Elbert 2016-07-05 11:19:18 -05:00
parent c0d43171a4
commit 30726ec1b8
2 changed files with 22 additions and 5 deletions

View File

@ -0,0 +1,17 @@
class IngredientDecorator < BaseDecorator
def ndbn_check
if ndbn.present?
"<span class =\"glyphicon glyphicon-ok\"></span>".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

View File

@ -16,22 +16,22 @@
<thead>
<tr>
<th>Name</th>
<th>USDA NDBN</th>
<th>USDA</th>
<th>KCal per 100g</th>
<th>Density</th>
<th>Density (oz/cup)</th>
<th></th>
</tr>
</thead>
<tbody>
<% @ingredients.each do |ingredient| %>
<% decorate(@ingredients, IngredientDecorator).each do |ingredient| %>
<tr>
<td><%= link_to ingredient.name, edit_ingredient_path(ingredient) %></td>
<td><%= ingredient.ndbn %></td>
<td><%= ingredient.ndbn_check %></td>
<td><%= ingredient.kcal %></td>
<td><%= ingredient.density %></td>
<td>
<%= 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 %>
<span class="glyphicon glyphicon-remove"></span>
<% end %>
</td>