Get real IP address in local Rails development environment

前端 未结 8 608
眼角桃花
眼角桃花 2020-11-30 23:15

I have Rails 2.3.8, Ruby 1.8.7, Mongrel Web Server and MySQL database.

I am in the development mode and I need to find the real IP address

8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-30 23:41

    This is what I normally do nowadays:

    if Rails.env.production?
      request.remote_ip
    else
      Net::HTTP.get(URI.parse('http://checkip.amazonaws.com/')).squish
    end
    

提交回复
热议问题