Rails获取客户端IP地址

Rails获取客户端IP地址
2010-03-26 21:47

Example Rails Code

In RAILS_ROOT/app/controllers/show_my_ip_controller.rb:

  1. class ShowMyIpController < ApplicationController  
  2.   
  3.   def index  
  4.     @client_ip = request.remote_ip  
  5.   end  
  6.   
  7. end  

In RAILS_ROOT/app/views/show_my_ip/index.html.erb:

  1. Your IP address is <%= @client_ip %> 


原文地址:https://www.cnblogs.com/lexus/p/2146345.html