From 546f1d4cbd63463993d58f524bd348301b3de5d4 Mon Sep 17 00:00:00 2001 From: Godwin Date: Sat, 5 Jul 2014 17:17:47 -0600 Subject: [PATCH] Fixes for orgs-json --- app/controllers/organizations_controller.rb | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index bf438b3..b5beeeb 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -1,4 +1,5 @@ include ApplicationHelper +require 'uri' class OrganizationsController < ApplicationController before_action :set_organization, only: [:show, :edit, :update, :destroy] @@ -100,13 +101,14 @@ class OrganizationsController < ApplicationController countries[location.country.downcase][:territories][location.territory.downcase] = country.subregions.coded(location.territory) end territory = countries[location.country.downcase][:territories][location.territory.downcase] - if !orgs[location.country.downcase][location.territory.downcase].has_key?(location.territory.downcase) - orgs[location.country.downcase][location.territory.downcase][location.city.downcase] = Hash.new - orgs[location.country.downcase][location.territory.downcase][location.city.downcase][:latitude] = location.latitude - orgs[location.country.downcase][location.territory.downcase][location.city.downcase][:longitude] = location.longitude - orgs[location.country.downcase][location.territory.downcase][location.city.downcase][:count] = 0 + city = URI.encode(location.city.downcase.gsub(/\s/, '-')) + if !orgs[location.country.downcase][location.territory.downcase].has_key?(city) + orgs[location.country.downcase][location.territory.downcase][city] = Hash.new + orgs[location.country.downcase][location.territory.downcase][city][:latitude] = location.latitude + orgs[location.country.downcase][location.territory.downcase][city][:longitude] = location.longitude + orgs[location.country.downcase][location.territory.downcase][city][:count] = 0 end - orgs[location.country.downcase][location.territory.downcase][location.city.downcase][orgs[location.country.downcase][location.territory.downcase][location.city.downcase][:count]] = { + orgs[location.country.downcase][location.territory.downcase][city][orgs[location.country.downcase][location.territory.downcase][city][:count]] = { :title => org.name, :id => org.id, :logo => org.avatar.url(:thumb), @@ -126,7 +128,7 @@ class OrganizationsController < ApplicationController :url => url_for(org), :order => order } - orgs[location.country.downcase][location.territory.downcase][location.city.downcase][:count] += 1 + orgs[location.country.downcase][location.territory.downcase][city][:count] += 1 order += 1 } render :json => orgs.to_json