0

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

David Dsr
  • 327
  • 2
  • 5
  • 19
  • have you tried by adding following method in `ActionDispatch::Request` class. `def location '81.38.174.158' end` – Amit Sharma Apr 16 '15 at 17:57
  • I've tried that but def remote_ip instead of def location. Any way I've just tried with def location and if I do def location '81.38.174.158' end and I do ap request.location gives me just this => '81.38.174.158' – David Dsr Apr 16 '15 at 18:27
  • then i think your issue is resolved? – Amit Sharma Apr 16 '15 at 18:29
  • not at all. request.location is a hash with a few keys and values, like this: "79.108.199.230", "city"=>"", "region_code"=>"", "region_name"=>"", "metrocode"=>"", "zipcode"=>"", "latitude"=>"0", "longitude"=>"0", "country_name"=>"Reserved", "country_code"=>"RD"}, @cache_hit=nil> If you notice I have got to set the ip to "79.108.199.230" but it keeps giving me "latitude"="0" and "location"="0" when I expected to give me the correct coordinates of where I am now – David Dsr Apr 16 '15 at 18:44
  • Ok i've found out what's going on. It was a problem of limit time in Geocoder http://stackoverflow.com/questions/18285240/error-in-request-location-ruby-geocoder Thanks a lot¡¡ – David Dsr Apr 16 '15 at 19:07

0 Answers0