Geocoder, how to test locally when ip is 127.0.0.1?

前端 未结 6 1790
盖世英雄少女心
盖世英雄少女心 2020-12-04 18:16

I can\'t get geocoder to work correct as my local ip address is 127.0.0.1 so it can\'t located where I am correctly.

The request.location.ip shows \"127.0.0.1\"

6条回答
  •  感情败类
    2020-12-04 19:01

    For this I usually use params[:ip] or something in development. That allows me to test other ip addresses for functionality and pretend I'm anywhere in the world.

    For example

    class ApplicationController < ActionController::Base
      def request_ip
        if Rails.env.development? && params[:ip]
          params[:ip]
        else
          request.remote_ip
        end 
      end
    end
    

提交回复
热议问题