Note that there are some explanatory texts on larger screens.

plurals
  1. PORuby Geocoder gem to find postal code
    primarykey
    data
    text
    <p>I'm using the ruby geocoder gem to search by location. I want to limit searches to locations that have officially launched. If someone searches by zip, this is easy using a regex. But if someone searches by city, I need to convert the city into a zip code, check my zip table and if positive, return the search results. </p> <p>The <a href="http://rubydoc.info/gems/geocoder/frames" rel="nofollow">geocoder api</a> has a section for reverse geocoding: </p> <pre><code>reverse_geocoded_by :latitude, :longitude do |obj,results| if geo = results.first obj.city = geo.city obj.zipcode = geo.postal_code obj.country = geo.country_code end end after_validation :reverse_geocode </code></pre> <p>This is obviously built just for using in the model. But I'm attempting to use it within my controller, but obj.zipcode is not working much at all. Geocoder.search('san jose, ca') seems to return what i need, i just don't know how to get to it. Here's where I'm at:</p> <pre><code> if params[:search].present? # coords = Geocoder.coordinates(params[:search]) zip = Geocoder.search(params[:search]) if Zip.where(:zip =&gt; (params[zip.zipcode]), :launch =&gt; true).exists? addresses = Address.near(params[:search], 25, :order =&gt; :distance) @profiles = addresses.map{ |ad| ad.profile }.uniq unless addresses.nil? @title = "Addresses Near " + (params[:search]).to_s else if Zip.where(:zip =&gt; (params[zip.zipcode]), :nearlaunch =&gt; true).exists? addresses = Address.near(params[:search], 25, :order =&gt; :distance) @profiles = addresses.map{ |ad| ad.profile }.uniq unless addresses.nil? @title = "We have not launched for your location but these are near by " + (params[:search]).to_s else redirect_to :controller =&gt; 'pages', :action =&gt; 'notlaunched' end end </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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