From cd1a0548ba9a1def3105959f7242ce29cb1b8ec5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Wed, 7 Mar 2018 17:49:38 +0100 Subject: [PATCH] Add `map_location#json_data` method --- app/helpers/budgets_helper.rb | 11 +---------- app/models/map_location.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/app/helpers/budgets_helper.rb b/app/helpers/budgets_helper.rb index 85a727600..fc20c36a9 100644 --- a/app/helpers/budgets_helper.rb +++ b/app/helpers/budgets_helper.rb @@ -65,15 +65,6 @@ module BudgetsHelper end def current_budget_map_locations - current_budget.investments.map do |investment| - next unless investment.map_location.present? - { - lat: investment.map_location.latitude, - long: investment.map_location.longitude, - investment_title: investment.title, - investment_id: investment.id, - budget_id: current_budget.id - } - end.flatten.compact + MapLocation.where(investment_id: current_budget.investments).map { |l| l.json_data } end end diff --git a/app/models/map_location.rb b/app/models/map_location.rb index 3b0b2b3c0..590eeb284 100644 --- a/app/models/map_location.rb +++ b/app/models/map_location.rb @@ -9,4 +9,12 @@ class MapLocation < ActiveRecord::Base latitude.present? && longitude.present? && zoom.present? end + def json_data + { + id: id, + lat: latitude, + long: longitude + } + end + end