Browse Source

Preparing for deployment to new server

development
Godwin 11 years ago
parent
commit
930aa130d6
  1. 3
      Gemfile
  2. 18
      Gemfile.lock
  3. 51
      app/controllers/organizations_controller.rb
  4. 1
      config/routes.rb
  5. 2
      lib/tasks/migrate.rake

3
Gemfile

@ -55,4 +55,7 @@ end
group :staging, :production do
gem 'rails_12factor'
gem 'capistrano'
gem 'rvm-capistrano'
gem 'unicorn' if !(RbConfig::CONFIG['target_os'] =~ /mswin|mingw|cygwin/i)
end

18
Gemfile.lock

@ -59,6 +59,12 @@ GEM
debug_inspector (>= 0.0.1)
builder (3.1.4)
callsite (0.0.11)
capistrano (2.15.5)
highline
net-scp (>= 1.0.0)
net-sftp (>= 2.0.0)
net-ssh (>= 2.0.14)
net-ssh-gateway (>= 1.1.0)
capybara (2.2.1)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
@ -140,6 +146,7 @@ GEM
activesupport (~> 4.0.0)
haml (>= 3.1, < 5.0)
railties (~> 4.0.0)
highline (1.6.21)
hike (1.2.3)
httpauth (0.2.1)
i18n (0.6.9)
@ -175,6 +182,13 @@ GEM
multi_json (1.10.0)
multipart-post (2.0.0)
nested_form (0.3.2)
net-scp (1.2.1)
net-ssh (>= 2.6.5)
net-sftp (2.1.2)
net-ssh (>= 2.6.5)
net-ssh (2.9.1)
net-ssh-gateway (1.2.0)
net-ssh (>= 2.6.5)
nokogiri (1.6.2.1-x86-mingw32)
mini_portile (= 0.6.0)
oauth (0.4.7)
@ -240,6 +254,8 @@ GEM
rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0)
rubyzip (1.1.3)
rvm-capistrano (1.5.2)
capistrano (~> 2.15.4)
safe_yaml (1.0.3)
sass (3.2.19)
sass-rails (4.0.3)
@ -303,6 +319,7 @@ DEPENDENCIES
awesome_print
better_errors
binding_of_caller
capistrano
capybara
carmen!
carmen-rails
@ -333,6 +350,7 @@ DEPENDENCIES
rails_12factor
rspec
rspec-rails
rvm-capistrano
sass-rails (~> 4.0.0)
selenium-webdriver
simplecov

51
app/controllers/organizations_controller.rb

@ -12,6 +12,9 @@ class OrganizationsController < ApplicationController
# GET /organizations/1
def show
if params[:slug] == 'json'
json
end
end
# GET /organizations/new
@ -81,6 +84,54 @@ class OrganizationsController < ApplicationController
set_organization
end
def json
orgs = Hash.new
order = 0
countries = Hash.new
Organization.find(:all, :joins => :locations, :order => 'locations.latitude').each { |org|
location = org.locations.first
if !orgs.has_key?(location.country.downcase)
orgs[location.country.downcase] = Hash.new
countries[location.country.downcase] = { :country => Carmen::Country.coded(location.country), :territories => Hash.new }
end
country = countries[location.country.downcase][:country]
if !orgs[location.country.downcase].has_key?(location.territory.downcase)
orgs[location.country.downcase][location.territory.downcase] = Hash.new
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.territory.downcase] = Hash.new
orgs[location.country.downcase][location.territory.downcase][location.territory.downcase][:latitude] = location.latitude
orgs[location.country.downcase][location.territory.downcase][location.territory.downcase][:longitude] = location.longitude
orgs[location.country.downcase][location.territory.downcase][location.territory.downcase][:count] = 0
end
orgs[location.country.downcase][location.territory.downcase][location.territory.downcase][orgs[location.country.downcase][location.territory.downcase][location.territory.downcase]['count']] = {
:title => org.name,
:id => org.id,
:logo => org.avatar.url(:thumb),
:logo_large => org.avatar.url,
:location => {
:street => location.street,
:city => location.city,
:province => location.territory,
:country => country.name,
:province_name => territory ? territory.name : nil,
:country_name => country.name,
:latitude => location.latitude,
:longitude => location.longitude
},
:website => org.url,
:year_founded => org.year_founded,
:url => url_for(org),
:order => order
}
orgs[location.country.downcase][location.territory.downcase][location.territory.downcase][:count] += 1
order += 1
}
render :json => orgs.to_json
end
private
# Use callbacks to share common setup or constraints between actions.
def set_organization

1
config/routes.rb

@ -30,6 +30,7 @@ BikeBike::Application.routes.draw do
resources :organizations, :param => 'slug' do
get :members
get :identity
get :json
post :nonmembers
end

2
lib/tasks/migrate.rake

@ -293,7 +293,7 @@ namespace :migrate do
while !data && attempts < 10
if attempts > 0
sleep 2
puts "Download failed, attempt #{attempt + 1} to obtain #{type.singularize} data from live server"
puts "Download failed, attempt #{attempts + 1} to obtain #{type.singularize} data from live server"
end
begin
data = get_data(is_entity ? type.singularize : (vocabulary ? 'taxonomy_term' : 'node'), is_entity || vocabulary ? nil : table, vocabulary ? table : nil)

Loading…
Cancel
Save