0

I have an address saved as a cookie and now I want to pass it through geocoder to get it's lat and lng to show a map view.

the data that cookies[:location] has stored is {"location"=>"1 E 161 St, The Bronx, NY 10451"}, how do I get it so that just "1 E 161 St, The Bronx, NY 10451" is passed into Geocoder.search()?

1 Answers1

0

I figured it out. My problem was that cookies[:location] was a string of a hash.
Here is what worked:

<% hash = eval(cookies[:location])%>
<% hash["location"] %>


<% results = Geocoder.search(hash["location"]) %>
  • Using `eval` on a user provided cookie is a really bad idea. You should use the built in [Marshal class](https://ruby-doc.org/core-2.2.1/Marshal.html) or Yaml/JSON to actually solve the initial problem instead of just creating a vulnerability in your app. Or just don't store a hash in the first place. – max Apr 14 '19 at 20:00
  • I will look into Marshal class. The cookie is only being saved for a very short period of time, just enough to allow what the user submits into the form to populate the find nearby map. – DammitJanet Apr 15 '19 at 20:43