Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added support for missing urls.

  • Loading branch information...
commit 2fee561a61eded6216f3a3f91688ac6fb994d2a3 1 parent cfdedff
@bnolan authored
View
24 app/assets/javascripts/places.js.coffee
@@ -11,7 +11,7 @@ class GeocodeResult extends Backbone.Model
c.long_name
if @isEstablishment()
- pathComponents.unshift(place.get('name'))
+ pathComponents.unshift(@get('name'))
pathComponents = for c in pathComponents
c.toLowerCase().replace(/[-\s]+/g,'-')
@@ -57,7 +57,7 @@ class SearchView
@createMap()
@addAutocomplete()
-
+
onSubmit: (e) =>
e.preventDefault()
@@ -118,10 +118,22 @@ class SearchView
google.maps.event.addListener @autocomplete, 'place_changed', @onAutocomplete
onAutocomplete: =>
- window.place = place = new GeocodeResult(@autocomplete.getPlace())
-
- # console.log place
-
+ @savePlace(new GeocodeResult(@autocomplete.getPlace()))
+
+ resolveAndGoto: (path) ->
+ geocoder = new google.maps.Geocoder()
+
+ address = path.split('/').reverse().join(", ")
+
+ geocoder.geocode { 'address': address }, (results, status) =>
+ place = new GeocodeResult(results[0])
+
+ place.getPath = ->
+ path
+
+ @savePlace(place)
+
+ savePlace: (place) ->
place.save = ->
params = {
path : place.getPath()
View
4 app/controllers/places_controller.rb
@@ -16,7 +16,9 @@ def create
end
def show
- @place = Place.find_by_path(params[:path])
+ @path = params[:path]
+
+ @place = Place.find_by_path(@path)
render :action => :index
end
View
7 app/views/places/index.html.erb
@@ -14,6 +14,11 @@
<script>
$(function(){
- new SearchView(<%= @place.to_json.html_safe %>)
+ var view = new SearchView(<%= @place.to_json.html_safe %>)
+
+ <% if @path.present? and @place.nil? %>
+ // This is vulnerable to html injection...
+ view.resolveAndGoto(<%= @path.to_json.html_safe %>);
+ <% end %>
});
</script>
Please sign in to comment.
Something went wrong with that request. Please try again.