parsley/app/views/foods/index.json.jbuilder

20 lines
483 B
Ruby

json.cache_root! [Food.all, @foods] do
json.extract! @foods, :total_count, :total_pages, :current_page
json.page_size @foods.limit_value
json.foods @foods do |i|
json.extract! i, :id, :name, :ndbn, :kcal
json.usda i.ndbn.present?
if i.density.present?
value = UnitConversion::parse(i.density)
json.density value.convert('oz/cup').change_formatter(UnitConversion::DecimalFormatter.new).pretty_value
else
json.density nil
end
end
end