Rails 4 w/ Geocoder Get IP address during form submission -


i have installed geocoder gem , when user submits form, want use ip address automatically submit lat/lon database. having hard time finding tutorial this. i'm finding either using c/s/c submission or trying find distances using ip address isn't want. want take lat/lon , use them show user when submitted form both on user profile , on google map want save them.

with following setup, getting error:

nomethoderror in answerscontroller#create undefined method `ip_address' #<answer:0x007fc1cd589968> 

here form:

<%= form_for [@daily, @answer] |answer| %>   <%= answer.label :answer, "" %>   <%= answer.text_area :answer %><br>    <%= answer.label :tags, "tags (separate commas, use '-' multi-word tags"%>   <%= answer.text_field :tag_list %><br>    <%= answer.submit %> <% end %> 

here answers controller:

  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 

my answer model:

class answer < activerecord::base   belongs_to :question   belongs_to :user   acts_as_taggable   geocoded_by :ip_address   after_validation :geocode end 

i found helper method use during development (since localhost wont provide ip)

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 

i think need add

result = request.location 

but don't know where. tried adding answerscontroller didn't work.

thanks!


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -