getting Geocoder to detect hardcoded ip in dev env and display data

44 views Asked by At

Just installed Geocoder and trying to get it to show signs of life. I want a user to log in and have the profile landing page to show data on their ip. Since I'm in the dev environment, here is my attempt at a temporary solution:

class SessionsController 

  def create
    user = User.authenticate(params[:username_or_email], params[:password])
    if user
      session[:user_id] = user.id
      redirect_to profile_path, :notice => "Logged in!"
      @request = Rack::Request.new({'REMOTE_ADDR' => '107.128.188.218'})
      @location = @request.location
    #blah blah blah
  end

in the view:

<%= @location.data %>

the error I get is undefined method 'data' for nil:NilClass

in the intializers/geocoder.rb

Geocoder.configure(
  :timeout => 30
)
1

There are 1 answers

8
soupdog On BEST ANSWER

You are assigning ivars @request and @location in the create action of your SessionsController, but the lifetime of these variables is just that request. After the controller action finishes, you are redirecting the client's browser to your ProfilesController, so you need to move those two assignments into ProfilesController#show, then it should work.

EDIT: Since you say you are using the SessionsController show action for the user's profile, moving those two statements to that action method should do the trick. :-)