From b09b3eb19691420e36ba28c06685c3a77ae382f9 Mon Sep 17 00:00:00 2001 From: Dan Elbert Date: Thu, 20 Oct 2016 18:06:53 -0500 Subject: [PATCH] Added tags to homepage --- app/decorators/recipe_decorator.rb | 7 +++++++ app/models/recipe_ingredient.rb | 24 +++++++++++++----------- app/views/recipes/index.html.erb | 2 ++ app/views/recipes/show.html.erb | 2 ++ 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/app/decorators/recipe_decorator.rb b/app/decorators/recipe_decorator.rb index 49de7d2..4045d45 100644 --- a/app/decorators/recipe_decorator.rb +++ b/app/decorators/recipe_decorator.rb @@ -10,6 +10,13 @@ class RecipeDecorator < BaseDecorator end end + def tag_names + tags = wrapped.tag_names + tags.map do |t| + h.content_tag('span', t, class: 'label label-default') + end.join(' ').html_safe + end + def source_markup uri = begin URI.parse(self.source) diff --git a/app/models/recipe_ingredient.rb b/app/models/recipe_ingredient.rb index 4b3731b..939867d 100644 --- a/app/models/recipe_ingredient.rb +++ b/app/models/recipe_ingredient.rb @@ -67,18 +67,20 @@ class RecipeIngredient < ApplicationRecord end def to_mass - value_unit = as_value_unit - density = self.ingredient.density? ? UnitConversion.parse(ingredient.density) : nil + if ingredient + value_unit = as_value_unit + density = self.ingredient.density? ? UnitConversion.parse(ingredient.density) : nil - case - when value_unit.nil? - when value_unit.mass? - self.quantity = value_unit.pretty_value - self.units = value_unit.unit.to_s - when value_unit.volume? && density && density.density? - value_unit = value_unit.to_mass(density) - self.quantity = value_unit.pretty_value - self.units = value_unit.unit.to_s + case + when value_unit.nil? + when value_unit.mass? + self.quantity = value_unit.pretty_value + self.units = value_unit.unit.to_s + when value_unit.volume? && density && density.density? + value_unit = value_unit.to_mass(density) + self.quantity = value_unit.pretty_value + self.units = value_unit.unit.to_s + end end end diff --git a/app/views/recipes/index.html.erb b/app/views/recipes/index.html.erb index b97878d..b6d1148 100644 --- a/app/views/recipes/index.html.erb +++ b/app/views/recipes/index.html.erb @@ -18,6 +18,7 @@ <%= index_sort_header('Name', :name, @criteria) %> + Tags <%= index_sort_header('Rating', :rating, @criteria) %> Yields <%= index_sort_header('Time', :total_time, @criteria) %> @@ -32,6 +33,7 @@ <% decorate(@recipes, RecipeDecorator).each do |recipe| %> <%= link_to recipe.short_name, recipe %> + <%= recipe.tag_names %> <% if recipe.rating %> <%= text_field_tag('rating', recipe.rating, disabled: true, data: {rating: true, size: '20px', interval: '0.25'}) %> diff --git a/app/views/recipes/show.html.erb b/app/views/recipes/show.html.erb index 6120783..b255bcb 100644 --- a/app/views/recipes/show.html.erb +++ b/app/views/recipes/show.html.erb @@ -9,6 +9,8 @@ <% if @scale %> <%= @scale %> X <% end %> +
+ <%= @recipe.tag_names %>