module CloudFlareLocalizable

This module can be included in any Rails controller that needs country information. You get a helper method called cf_country to be used whenever you need to know the country of the user.

Example

class ExampleController < ApplicationController
  include CloudFlareLocalizable

  def index
    cf_country.code # => "BB"
    cf_country.name # => "Barbados"
  end
end

Constants

CF_COUNTRIES

Countries

CF_HEADER
VERSION

Public Class Methods

included(base) click to toggle source
# File lib/cloudflare_localizable.rb, line 22
def self.included(base)
  base.send(:helper_method, :cf_country)
end

Public Instance Methods

cf_country() click to toggle source

Returns the real name of the country, based on the country code.

# File lib/cloudflare_localizable.rb, line 27
def cf_country
  @cf_country ||= Country.find(request.headers[CF_HEADER] || 'XX')
end