I know this question is been asked many times before but I've checked the answers and it doesn't work for me as it should. I need to fake the ip adress of my localhost to not be '127.0.0.1' but '12.34.567.890' instead. I'm using Mongoid search and my final goal is to get distance_between([me], [spot.location]). So I need my real coordinates.
In internet I've found this solution:
module ApplicationHelper
class ActionDispatch::Request
def remote_ip
'81.38.174.158'
end
end
end
But it doesn't work because when I do in my searchesController ap request.location it keeps giving me an object with an ip '127.0.0.1'. and longitude and latitude = 0 obviusly. But if I do request.remote_ip the console gives me the right ip inside a string '12.34.567.890'. I don't understand why.
This is the code of controller/searches_controller.rb
class SearchesController < ApplicationController
def index
ap request.remote_ip
ap request.location
@user = current_user if current_user
@spots = Spot.full_text_search(params[:query])
@spots = Spot.order_by_distance @spots
end
end
This is what console gives me when I execute a search
"12.34.567.890" (The right ip) #"127.0.0.1", "city"=>"", "region_code"=>"", "region_name"=>"", "metrocode"=>"", "zipcode"=>"", "latitude"=>"0", "longitude"=>"0", "country_name"=>"Reserved", "country_code"=>"RD"}, @cache_hit=nil> Completed 500 Internal Server Error in 140ms