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

  • Home
  • SEARCH
  • 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 6713325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:22:00+00:00 2026-05-26T08:22:00+00:00

Another true newbie on Ruby here, so please be gentle… I’m working with alexreisner’s

  • 0

Another true newbie on Ruby here, so please be gentle…
I’m working with alexreisner’s Geocoder on rails 3.0 and am unable to call methods from the Geocoder::Results lib. I’ve pored over the Geocoder documentation, but I can’t accomplish one simple thing: pull out a “state” result from a user-submitted address. So turn “123 Fake Street, San Francisco, CA” into “CA” or “California.”

(My program will only use the “state” information for now to help determine results, but I’d like to have full address information to use at a later date when I refine the app, which is why I ask for a full address.)

I’ve set up my model via the best I have been able to gather from the documentation and other answers I’ve found here, but previous answers similar to this subject have not helped me:

class Project < ActiveRecord::Base                    
  attr_accessible :title, :address, :latitude, :longitude     

  belongs_to :user 

  geocoded_by :address
  after_validation :fetch_coordinates

  reverse_geocoded_by :latitude, :longitude do |obj, geo| 
    obj.state = geo.state
    obj.country_code = geo.country_code
    obj.address = [geo.state, geo.country_code].join(",")
  end
  after_validation :reverse_geocode  

end

But this turns up an “undefined error method” for state, country code and address. I don’t understand because the documentation for the Geocoder gem clearly provides these methods. My model seems simply unable to access them. (For the record, my model IS able to pull latitude and longitude from an entered address, so it does seem Geocoder is configured correctly. And the method “geocoded_by” works great. Furthermore, it is properly set to the Google API).

I’m pretty sure I’m missing something straightforward here. In the rails console, I’m even able to use Geocoder.search(“Miami, FL”) and pull all county, state and city information, but I just can’t seem to extract “state” via my model.

Thanks for any help!

  • 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-26T08:22:01+00:00Added an answer on May 26, 2026 at 8:22 am

    If you look at the examples on the Geocoder site, you’ll see that the second value yielded to the block seems to be an array or some other form of collection, so you can’t directly call the methods on it. Instead you first have to pull the right object out of it:

    reverse_geocoded_by :lat, :lon do |obj,results|
      if geo = results.first
        obj.city    = geo.city
        obj.zipcode = geo.postal_code
        obj.country = geo.country_code
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Annoying newbie problem here. This variable isPlayerTouchingAnotherPlayer is being set to true as soon
MaintainScrollPositionOnPostback = true its working with IE but not with mozilla(version 9) suggest another
Another basic Rails question: I have a database table that needs to contain references
another newbie question, Right after I save an item to database, I tried to
Is there a way I can check if a function is true inside another
i am a newbie to the design patterns and here is my question if
I'm a relative newbie at Rails, so forgive me if my question's got an
Another interview question which was expecting a true / false answer and I wasn't
This method return true if one CGRect intersects with another. Is there any possibility
Newbie here. I am trying to store the result of my search onto a

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.