Friday, March 26, 2010

Get IP address of the site visitor in rails application

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 %>

0 comments: