app/helpers/geo_helper.rb
# Returns the ISO-639-2 country code for the given IP address
#
# === Parameters
#
# [ip] the IPv4 address to look up. If not specified, the current request IP address will be used instead.
Returns the ISO-639-2 country code for the given IP address
Parameters

[ip] the IPv4 address to look up. If not specified, the current request IP address will be used instead.
Returns the ISO - 639 - 2 country code for the given IP address Parameters [ ip ] the IPv4 address to look up . If not specified the current request IP address will be used instead .
def country_code_for( ip = nil )
    conn = ActiveRecord::Base.connection
    quoted_ip = conn.quote( ip || request.ip )
    sql = "SELECT `country` FROM `stats_ip_blocks` " +
          "WHERE MBRCONTAINS( `ip_range`, POINTFROMWKB(POINT(INET_ATON( #{quoted_ip} ), 0)))"
    res = conn.execute( sql )
    ( res.count == 0 ? nil : res.first.first )
  end
def country_code_for ( ip = nil ) conn = ActiveRecord :: Base . connection quoted_ip = conn . quote ( ip || request . ip ) sql = "SELECT `country` FROM `stats_ip_blocks` " + "WHERE MBRCONTAINS( `ip_range`, POINTFROMWKB(POINT(INET_ATON( #{quoted_ip} ), 0)))" res = conn . execute ( sql ) ( res . count == 0 ? nil : res . first . first ) end
Returns the ISO-639-2 country code for the given IP address
 Parameters
Returns the ISO - 639 - 2 country code for the given IP address Parameters
# get a DB connection # get a current IP, if not specified # lookup + return
ip