Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6036989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:00:26+00:00 2026-05-23T06:00:26+00:00

I am using the gem ‘geocoder’. I am trying to make an object that

  • 0

I am using the gem ‘geocoder’.
I am trying to make an object that will fetch the latitude and longitude from ip address.

This is how my object’s model looks like:

class Hey < ActiveRecord::Base

  geocoded_by :ip
  after_validation :geocode

  def ip
    return request.ip
  end

end

When I create an object I get this error:

NoMethodError (undefined method `request'for #<Hey:0x7f268f47dd00>):

if I change the method ip to:

  def ip
    return "24.193.83.1"
  end

it works. Why does request.ip doesn’t work in the model ?
request.ip works for me in the controller.

How can I fix this?

Thanks,

Oded

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T06:00:27+00:00Added an answer on May 23, 2026 at 6:00 am

    This is how I solved it.

    the model:

    class Hey < ActiveRecord::Base
    
          attr_accessor :ip_address
    
          geocoded_by :ip_address
          after_validation :geocode
    
        end
    

    controller:

    class HeysController < ApplicationController
    
     def create
            hey = Hey.new
            hey.ip_address = request.ip
            hey.save
    
            redirect_to :action => "index"
          end
    
     end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm deploying to Ubuntu slice on slicehost, using Rails 2.1.0 (from gem ) If
I am working on creating a daemon in Ruby using the daemons gem. I
I'm implementing charts using The Ziya Charts Gem . Unfortunately, the documentation isn't really
We're thinking about using the rufus-scheduler gem on a Ruby on Rails project to
I am using the ruby daemons gem to create a custom daemon for my
Using ASP.NET MVC there are situations (such as form submission) that may require a
Using C# .NET 3.5 and WCF, I'm trying to write out some of the
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
When I download something using gem I'd like to be able to just download
I'm using gem bundler (v.0.9.6) and Rails 2.3.5, rubygems 1.3.6 and ruby 1.8.7 (On

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.