Get real IP address in local Rails development environment

前端 未结 8 609
眼角桃花
眼角桃花 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条回答
  •  醉话见心
    2020-11-30 23:36

    I am testing with Rspec and what I did was:

    request.stub(:remote_ip).and_return('198.172.43.34')
    Instance.stub(:find_by_key).and_return(@instance)
    before = @instance.weekly_statistic.times_opened_by['198.172.43.34']
    
    get :key, :key=>"314C00"
    
    @instance.weekly_statistic.times_opened_by['198.172.43.34'].should == before+1
    

    And it worked like a charm! : )

提交回复
热议问题