Move current budget's geolocated investments code to helper function
This commit is contained in:
@@ -16,8 +16,7 @@ class BudgetsController < ApplicationController
|
||||
def index
|
||||
@budgets = @budgets.order(:created_at)
|
||||
@budget = current_budget
|
||||
budgets_map_locations = current_budget.investments.map{ |investment| investment.map_location }.compact
|
||||
@budgets_coordinates = budgets_map_locations.map{ |ml| {lat: ml.latitude, long: ml.longitude, investment_title: ml.investment.title , investment_id: ml.investment.id, budget_id: ml.investment.budget.id}}
|
||||
@budgets_coordinates = current_budget_map_locations
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -53,4 +53,16 @@ module BudgetsHelper
|
||||
!budget.drafting? || current_user&.administrator?
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user