I am building a website that can store body measurements and calculate body fat using jackson/ pollock 7 method formula. I am pretty new to rails and not sure how I can output the calculation from the measurements controller into the show.html.
Measurements_controller.rb calculate method:
def calculate
bodyDensityMale = 1.112 - (0.00043499 * (@measurement.chest + @measurement.Midaxillary + @[email protected][email protected]
[email protected][email protected])) + (0.00000055 * (@[email protected][email protected][email protected][email protected]
[email protected][email protected])^2) - (0.00028826 * @measurement.age)
bodyDensityFemale = 1.097 - (0.00046971 * (@measurement.chest + @[email protected][email protected][email protected]
[email protected][email protected])) + (0.00000056 * (@[email protected][email protected][email protected][email protected]
[email protected][email protected])^2) - (0.00012828 * @measurement.age)
bodyFatMale = (495 / bodyDensityMale) - 450
bodyFatFemale = (495 / bodyDensityFemale) - 450
if (@measurement.gender_type = 'Male')
puts bodyFatMale
else
puts bodyFatFemale
end
end
show.html.erb
<p>
<strong>Body Fat (%): </strong>
<%= @measurement.calculate %>
</p>
When I create the entry there are no errors but the Body fat % field shows up empty. I appreciate any help!