Rails获取客户端IP地址
2010-03-26 21:47
Example Rails Code
In RAILS_ROOT/app/controllers/show_my_ip_controller.rb:
- class ShowMyIpController < ApplicationController
- def index
- @client_ip = request.remote_ip
- end
- end
In RAILS_ROOT/app/views/show_my_ip/index.html.erb:
- Your IP address is <%= @client_ip %>
![](http://img.zemanta.com/pixy.gif?x-id=8b0c599c-146f-85cd-a43b-10eaf475ddcd)