fixed and re-enabled support for memcache in the production site
authorBenjamin Mako Hill <mako@ephesus.xvm.mit.edu>
Sun, 17 Jun 2012 22:42:57 +0000 (18:42 -0400)
committerBenjamin Mako Hill <mako@ephesus.xvm.mit.edu>
Sun, 17 Jun 2012 22:42:57 +0000 (18:42 -0400)
app/controllers/quickvote_controller.rb
config/environments/development.rb
config/environments/production.rb
config/environments/test.rb

index c32d585dd53cc441d8e36d7a72fe74be9edaec90..b57abaa40dfba69ab01d3912023e183bda8af771 100644 (file)
@@ -161,7 +161,7 @@ class QuickvoteController < ApplicationController
     else
       
       # record the ip address for posterity
-      @voter.ipaddress = request.env["REMOTE_ADDR"]
+      @voter.ipaddress = request.env["HTTP_X_FORWARDED_FOR"]
       @voter.save
       
       # toggle the confirmation bit      
@@ -186,9 +186,10 @@ class QuickvoteController < ApplicationController
     @election=QuickVote.ident_to_quickvote(params[:id])
     @election.voters.each do |voter|
       next unless voter.ipaddress
+
       location=nil
-      if defined? Cache and location=Cache.get("GEO:#{voter.ipaddress}")
-      elsif defined? Cache
+      if Cache and location=Cache.get("GEO:#{voter.ipaddress}")
+      elsif Cache
         location = GeoKit::Geocoders::IpGeocoder.geocode(voter.ipaddress)
         Cache.set "GEO:#{voter.ipaddress}", location
       else
index 2d7f9789e0a4bf8cb1e9388defc71e218665520f..669f755c2473357389d4e4b82779d98e5e912c56 100644 (file)
@@ -1,6 +1,7 @@
 # Settings specified here will take precedence over those in config/environment.rb
 #disable memcache
 Cache=nil
+
 # In the development environment your application's code is reloaded on
 # every request.  This slows down response time but is perfect for development
 # since you don't have to restart the webserver when you make code changes.
index 20ded00559a49d05e95a180342e910687db7bcfd..4bb13510ef6ff610417fb7dd61803e5795e8eee1 100644 (file)
@@ -1,9 +1,9 @@
 # Settings specified here will take precedence over those in config/environment.rb
 #
 #Enable memcache
-#require('memcache')
-#Cache=MemCache.new('localhost', :compression => true)
-Cache=nil
+require('memcache')
+Cache=MemCache.new('localhost', :compression => true)
+
 # The production environment is meant for finished, "live" apps.
 # Code is not reloaded between requests
 config.cache_classes = true
index a1a2608bbfd3ef55531c08d37403266a0d7d463f..f1ab738a22a3a4c59c118b6aca242243cd81312f 100644 (file)
@@ -1,6 +1,7 @@
 # Settings specified here will take precedence over those in config/environment.rb
 #disable memcache
 Cache=nil
+
 # The test environment is used exclusively to run your application's
 # test suite.  You never need to work with it otherwise.  Remember that
 # your test database is "scratch space" for the test suite and is wiped

Benjamin Mako Hill || Want to submit a patch?