title: Rails 4 w/ Geocoder Get IP address during form submission
body: <p>I have installed the Geocoder Gem and when a user submits a form, I want to use their IP address to automatically submit their lat/lon to my database.  I am having a hard time finding a tutorial for this.  Everything I'm finding is either using c/s/c submission or trying to find distances using IP address which isn't what I want.  Eventually I want to take the lat/lon and use them to show where the user was when they submitted the form both on their user profile and on a google map but for now I just want to save them.</p>
  
  <p>With the following setup, I am getting this error:</p>
  
  <pre><code>NoMethodError in AnswersController#create
  undefined method `ip_address' for #&lt;Answer:0x007fc1cd589968&gt;
  </code></pre>
  
  <p>Here is my form:</p>
  
  <pre><code>&lt;%= form_for [@daily, @answer] do |answer| %&gt;
    &lt;%= answer.label :answer, "" %&gt;
    &lt;%= answer.text_area :answer %&gt;&lt;br&gt;
  
    &lt;%= answer.label :tags, "Tags (separate by commas, use '-' with multi-word tags"%&gt;
    &lt;%= answer.text_field :tag_list %&gt;&lt;br&gt;
  
    &lt;%= answer.submit %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>Here is my answers controller:</p>
  
  <pre><code>  def new
      @daily = Question.find_by(show_month: Time.now.month, show_day: Time.now.day)
      @answer = Answer.new
    end
  
    def create
      @question = Question.find(params[:question_id])
      @answer = Answer.new( answer_params )
      @answer.user_id = current_user.id
      @answer.question_id = @question.id
      if @answer.save
        redirect_to @question
      else
        render 'new'
      end
    end
  
    def answer_params
      params.require(:answer).permit(:answer, :user_id, :question_id, :tag_list, :latitude, :longitude)
    end
  </code></pre>
  
  <p>my answer model:</p>
  
  <pre><code>class Answer &lt; ActiveRecord::Base
    belongs_to :question
    belongs_to :user
    acts_as_taggable
    geocoded_by :ip_address
    after_validation :geocode
  end
  </code></pre>
  
  <p>I also found this helper method to use during development (since localhost wont provide an IP)</p>
  
  <pre><code>def location
    if params[:location].blank?
      if Rails.env.test? || Rails.env.development?
        @location ||= Geocoder.search("50.78.167.161").first
      else
        @location ||= request.location
      end
    else
      params[:location].each {|l| l = l.to_i } if params[:location].is_a? Array
      @location ||= Geocoder.search(params[:location]).first
      @location
    end
  end
  </code></pre>
  
  <p>I think I need to add </p>
  
  <pre><code>result = request.location
  </code></pre>
  
  <p>but I don't know where. I tried adding it to the AnswersController but that didn't work.</p>
  
  <p>Thanks!</p>