- 浏览: 2045090 次
- 性别:
- 来自: NYC
文章分类
- 全部博客 (628)
- Linux (53)
- RubyOnRails (294)
- HTML (8)
- 手册指南 (5)
- Mysql (14)
- PHP (3)
- Rails 汇总 (13)
- 读书 (22)
- plugin 插件介绍与应用 (12)
- Flex (2)
- Ruby技巧 (7)
- Gem包介绍 (1)
- javascript Jquery ext prototype (21)
- IT生活 (6)
- 小工具 (4)
- PHP 部署 drupal (1)
- javascript Jquery sort plugin 插件 (2)
- iphone siri ios (1)
- Ruby On Rails (106)
- 编程概念 (1)
- Unit Test (4)
- Ruby 1.9 (24)
- rake (1)
- Postgresql (6)
- ruby (5)
- respond_to? (1)
- method_missing (1)
- git (8)
- Rspec (1)
- ios (1)
- jquery (1)
- Sinatra (1)
最新评论
-
dadadada2x:
user模型里加上 protected def email ...
流行的权限管理 gem devise的定制 -
Sev7en_jun:
shrekting 写道var pattern = /^(0| ...
强悍的ip格式 正则表达式验证 -
jiasanshou:
好文章!!!
RPM包rpmbuild SPEC文件深度说明 -
寻得乐中乐:
link_to其实就是个a标签,使用css控制,添加一个参数: ...
Rails在link_to中加参数 -
aiafei0001:
完全看不懂,不知所然.能表达清楚一点?
"$ is not defined" 的问题怎么办
对于Rails而言,主流方式应该是使用google库的插件geoip
github地址如下
require 'geoip' GeoIP.new('GeoLiteCity.dat').country('www.atlantis.sk') => ["www.atlantis.sk", "217.67.18.26", "SK", "SVK", "Slovakia", "EU", "02", "Bratislava", "", 48.15, 17.1167, nil, nil, "Europe/Bratislava"] Returned values are the requested hostname, the IP address as a dotted quad, Maxmind's country code, the ISO3166-1 country code, the ISO3166-2 country code, the ISO3166 country name, and the continent code. GeoIP.new('GeoCity.dat').city('github.com') => ["github.com", "207.97.227.239", "US", "USA", "United States", "NA", "CA", "San Francisco", "94110", 37.7484, -122.4156, 807, 415, "America/Los_Angeles"] Returned values are the country values followed by region or state name, city name, postal_code/zipcode, latitude, longitude, USA DMA code, USA area code, timezone name. Sorry it's not a Hash... historical. GeoIP.new('GeoIPASNum.dat').asn("www.fsb.ru") => ["AS8342", "RTComm.RU Autonomous System"]
另外一个 geo_ip
使用如下:
GeoIp.geolocation(ip_address)
# 209.85.227.104 = google.be (US) GeoIp.geolocation('209.85.227.104') #returns: { :status =>"OK", :ip =>"209.85.227.104" :country_code =>"US", :country_name =>"United States", :region_code =>"06", :region_name =>"California", :city =>"Mountain View", :zip_postal_code =>"94043", :latitude =>"37.4192", :longitude =>"-122.057" }
geokit是一个关于地理的工具,比如根据经纬度确定城市和距离之类
#Find near latitude and longitude: Store.find(:all, :origin =>[37.792,-122.393], :within=>10) #Find near an address: Store.find(:all, :origin=>'100 Spear st, San Francisco, CA', :within=>10) #Order by distance from the center of a zipcode: Store.find(:all, :origin=>'94117', :within=>10, :order=>'distance asc') #Combine distance conditions with regular conditions Store.find(:all, :origin=>'94117', :within=>10, :conditions=>{:store_type=>'CAFE'})
一个是通过网络的IP查询API,这个办法IP库更新比较快。通用的库有几个比如google。
xml处理页面完全可以通过nokogiri等专门处理工具代替
提供IP地址查询的API很多比如网易
http://www.youdao.com/smartresult-xml/search.s?type=ip&q=IP地址
require 'net/http' require 'rexml/document' include REXML class MapsController < ApplicationController def index @location = locateIp() end def locateIp #ip = "123.123.123.123"; ip = request.remote_ip ips = ip.to_s url = "http://ipinfodb.com/ip_query.php?ip="+ips+"&timezone=false" xml_data = Net::HTTP.get_response(URI.parse(url)).body xmldoc = REXML::Document.new(xml_data) # Now get the root element root = xmldoc.root city = "" regionName = "" countryName = "" # This will take country name... xmldoc.elements.each("Response/CountryName") { |e| countryName << e.text } # Now get city name... xmldoc.elements.each("Response/City") { |e| city << e.text } # This will take regionName... xmldoc.elements.each("Response/RegionName") { |e| regionName << e.text } ipLocation = city +", "+regionName+", "+countryName return ipLocation end #end of method locateIp end
发表评论
-
Destroying a Postgres DB on Heroku
2013-04-24 10:58 883heroku pg:reset DATABASE -
VIM ctags setup ack
2012-04-17 22:13 3206reference ctags --extra=+f --e ... -
alias_method_chain方法在3.1以后的替代使用方式
2012-02-04 02:14 3230alias_method_chain() 是rails里的一个 ... -
一些快速解决的问题
2012-01-19 12:35 1426问题如下: 引用Could not open library ... -
API service 安全问题
2011-12-04 08:47 1336这是一个长期关注的课题 rest api Service的 ... -
Module方法调用好不好
2011-11-20 01:58 1294以前说,用module给class加singleton方法,和 ... -
一个ajax和rails交互的例子
2011-11-19 01:53 1849首先,这里用了一个,query信息解析的包,如下 https: ... -
Rails 返回hash给javascript
2011-11-19 01:43 2229这是一个特别的,不太正统的需求, 因为,大部分时候,ajax的 ... -
关于Rubymine
2011-11-18 23:21 2219开个帖子收集有关使用上的问题 前一段时间,看到半价就买了。想 ... -
ruby中和javascript中,动态方法的创建
2011-11-18 21:01 1184class Klass def hello(*args) ... -
textmate快捷键 汇总
2011-11-16 07:20 8077TextMate 列编辑模式 按住 Alt 键,用鼠标选择要 ... -
Ruby面试系列六,面试继续面试
2011-11-15 05:55 1965刚才受到打击了,充分报漏了自己基础不扎实,不肯向虎炮等兄弟学习 ... -
说说sharding
2011-11-13 00:53 1422这个东西一面试就有人 ... -
rails面试碎碎念
2011-11-12 23:51 1891面试继续面试 又有问ru ... -
最通常的git push reject 和non-fast forward是因为
2011-11-12 23:29 17138git push To git@github.com:use ... -
Rails 自身的many to many关系 self has_many
2011-11-12 01:43 2670简单点的 #注意外键在person上people: id ... -
Rails 3下的 in place editor edit in place
2011-11-12 01:20 906第一个版本 http://code.google.com/p ... -
Heroku 的诡异问题集合
2011-11-11 07:22 1651开个Post记录,在用heroku过程中的一些诡异问题和要注意 ... -
SCSS 和 SASS 和 HAML 和CoffeeScript
2011-11-07 07:52 12889Asset Pipeline 提供了内建 ... -
Invalid gemspec because of the date format in specification
2011-11-07 02:14 2060又是这个date format的错误。 上次出错忘了,记录下 ...
相关推荐
字体配制文件 博文链接:https://babo.iteye.com/blog/72298
[Pragmatic Bookshelf] 敏捷网络应用开发 (Rails 4 实现) (英文版) [Pragmatic Bookshelf] Agile Web Development with Rails 4 (E-Book) ☆ 图书概要:☆ Rails just keeps on changing. Both Rails 3 and 4, as...
用rails实现的简单的简历系统,其中包括图片上传、验证码生成、数据查询、分页、日历、sort、邮件发送
在 Rails 实现用户注册和登录功能是非常方便的,比如可以使用 Devise 这类实现了完整功能的 gem 扩展包。也可以使用 Rails 自带的 has_secure_password 来自已打造。下面就是尝试使用 has_secure_password 来实现...
Knock - 为Rails API实现无缝JWT身份验证
rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails ...
npm-rails, 通过像DSL这样的Bundler支持 Rails的NPM npm Rails 项目的NPM支持。 它允许你使用bundler像DSL和rake任务来包括npm包。 这个基于Browserify的gem,用于捆绑包和解析依赖关系。安装将此行添加到你的应用...
《Rails之道》详细讨论了Rails的程序代码并通过分析Rails中的代码片段来深入解释它的功能,同时,《Rails之道》部分章节也摘录了一些API文档中的内容,使读者能够快速地找到对应的API文档、相关的示例代码以及深入...
Google Sign-In for Rails 实现将Google登录集成到您的Rails应用中
rails登陆注册
《Ruby on Rails Tutorial》中文版(原书第2版,涵盖 Rails 4) Ruby 是一门很美的计算机语言,其设计原则就是“让编程人员快乐”。David Heinemeier Hansson 就是看重了这一点,才在开发 Rails 框架时选择了 Ruby...
一个用Ruby on Rails搭建的图片分享的网站项目.完整源代码
Ruby on Rails Guides v2 - Ruby on Rails 4.2.5
[Pragmatic Bookshelf] Crafting Rails Applications Expert Practices for Everyday Rails Development (E-Book) ☆ 图书概要:☆ Rails 3 is a huge step forward. You can now easily extend the framework, ...
rails文档 rails api 英文
中文世界唯一一本Rails 4.0.0 + Ruby 2.0.0 的自學書籍
web开发敏捷之道-rails第二版,下载后因为版本的更新已经程序登录上的一些问题进行的代码调整。目前在最新版本上可以运行
shoppe-example, 在 Rails 中使用Shoppe平台的示例存储实现 这是一个 Rails 应用程序,它使用 Shoppe 构建。 它具有一个可以爱的设计,以充分演示Shoppe平台提供的功能以及它在 Rails 应用程序中的。 正在启动要开始...