ruby on rails - Using Geokit and Geocoding to print value -
i have model stop such.
class stop < activerecord::base geocoded_by :address after_validation :geocode acts_as_mappable defaults_units: :kms, lat_column_name: :latitude, lng_column_name: :longitude my stop table has field id,name,address,longitude,latitude
this table contains pre-populated data of bus stops. have small form user enters address.
<%= form_tag("/welcome/index", method: "post") %> <h5>current location</h5> <%= text_field_tag :address %> <p> <%= submit_tag("submit") %> </p> <% end %> then in controller capture address entered user , use geokit find bus stop closest user provided address such.
curaddress = params[:address] @curlonglat = geocoder.coordinates(curaddress) @answer = stop.closest(origin: @curlonglat) finally try print stop closest in view file such
<% if @answer%> <%= "#{@answer} "%> <% end %> my output #<stop::activerecord_relation:0x007faa485228e0>
i not sure did wrong?
as @answer instance of activerecord_relation:, looks have this
<%= @answer.first.address %>
Comments
Post a Comment