From fb7ddd947a1ffca45f46ffd2a58e701048b12210 Mon Sep 17 00:00:00 2001 From: Yan Date: Thu, 24 Aug 2017 18:18:52 +0630 Subject: [PATCH] update for check for menu item api --- .../restaurant/menu/_menu_item.json.jbuilder | 74 ++++++++++--------- 1 file changed, 39 insertions(+), 35 deletions(-) diff --git a/app/views/api/restaurant/menu/_menu_item.json.jbuilder b/app/views/api/restaurant/menu/_menu_item.json.jbuilder index 23c5061e..3f8b5358 100644 --- a/app/views/api/restaurant/menu/_menu_item.json.jbuilder +++ b/app/views/api/restaurant/menu/_menu_item.json.jbuilder @@ -1,47 +1,51 @@ # Format for attributes json attr_format = [] -# Format for attributes json -item.item_attributes.each do|attr_id| - menu_attr = MenuItemAttribute.find(attr_id) - if attr_format.count == 0 - attr_format.push({ type: menu_attr.attribute_type, values: [menu_attr.name] }) - next - end +# Format for attributes json +if item.item_attributes.count > 0 + item.item_attributes.each do|attr_id| + menu_attr = MenuItemAttribute.find(attr_id) + if attr_format.count == 0 + attr_format.push({ type: menu_attr.attribute_type, values: [menu_attr.name] }) + next + end - attr_format.each do |af| - if menu_attr.attribute_type.in? attr_format.map {|k| k[:type]} - if menu_attr.attribute_type == af[:type] - af[:values].push(menu_attr.name) - end - else - new_attr = {type: menu_attr.attribute_type, values: [ menu_attr.name ] } - attr_format.push(new_attr) - break - end + attr_format.each do |af| + if menu_attr.attribute_type.in? attr_format.map {|k| k[:type]} + if menu_attr.attribute_type == af[:type] + af[:values].push(menu_attr.name) + end + else + new_attr = {type: menu_attr.attribute_type, values: [ menu_attr.name ] } + attr_format.push(new_attr) + break + end + end end end # Format for option json opt_format = [] -# Format for attributes json -item.item_options.each do|opt| - menu_opt = MenuItemOption.find(opt) - if opt_format.count == 0 - opt_format.push({ type: menu_opt.option_type, values: [menu_opt.name] }) - next - end - - opt_format.each do |of| - if menu_opt.option_type.in? opt_format.map {|k| k[:type]} - if menu_opt.option_type == of[:type] - of[:values].push(menu_opt.name) - end - else - new_opt = {type: menu_opt.option_type, values: [ menu_opt.name ] } - opt_format.push(new_opt) - break +# Format for attributes json +if item.item_options.count > 0 + item.item_options.each do|opt| + menu_opt = MenuItemOption.find(opt) + if opt_format.count == 0 + opt_format.push({ type: menu_opt.option_type, values: [menu_opt.name] }) + next end - end + + opt_format.each do |of| + if menu_opt.option_type.in? opt_format.map {|k| k[:type]} + if menu_opt.option_type == of[:type] + of[:values].push(menu_opt.name) + end + else + new_opt = {type: menu_opt.option_type, values: [ menu_opt.name ] } + opt_format.push(new_opt) + break + end + end + end end #Menu Item Information