Note that there are some explanatory texts on larger screens.

plurals
  1. PORails Geocoder "undefined method error"
    primarykey
    data
    text
    <p>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."</p> <p>(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.)</p> <p>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:</p> <pre><code>class Project &lt; 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 </code></pre> <p>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). </p> <p>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. </p> <p>Thanks for any help!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload