Created
April 9, 2015 23:02
-
-
Save mahemoff/8ec27ebfe22b89c8669a to your computer and use it in GitHub Desktop.
Cloudflare country detection (geo-ip) in Ruby/Rails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController < ActionController::Base | |
def cloudflare_country_code | |
request.headers['HTTP_CF_IPCOUNTRY'] | |
end | |
def eu_request? | |
cloudflare_country_code.in? %w(GB FR DE ..... ) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This worked great for me.
To serve a different terms and conditions page to the EU I also added this to the appropriate controller: