1
0

Displaying errors for uncomputable formulas in nutrients view

This commit is contained in:
cryptogopher
2020-03-21 00:38:39 +01:00
parent 9a79e8fa55
commit c3b783e942
5 changed files with 22 additions and 7 deletions

View File

@@ -1,6 +1,13 @@
module BodyTrackersHelper
def format_value(value)
amount, unitname = value
amount.nil? ? '-' : "#{amount} [#{unitname || '-'}]"
case
when amount.nil?
'-'
when amount.nan?
'?'
else
"#{amount} [#{unitname || '-'}]"
end
end
end

View File

@@ -30,9 +30,6 @@ class Formula < ActiveRecord::Base
args << get_binding(quantities, args, length).eval(code)
end
args.last.map { |v| [v, nil] }
rescue Exception => e
puts e.message
[[nil, nil]] * length
end
private

View File

@@ -4,6 +4,8 @@
<% if @ingredients.any? %>
<%= render partial: 'ingredients/options' %>
<%= error_messages_for *@quantities.map { |q| q.formula } %>
<table class="nutrients list odd-even">
<thead>
<tr>