Skip to content

Commit

Permalink
Added support for missing urls.
Browse files Browse the repository at this point in the history
  • Loading branch information
bnolan committed Apr 29, 2013
1 parent cfdedff commit 2fee561
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
24 changes: 18 additions & 6 deletions app/assets/javascripts/places.js.coffee
Expand Up @@ -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,'-')
Expand Down Expand Up @@ -57,7 +57,7 @@ class SearchView

@createMap()
@addAutocomplete()

onSubmit: (e) =>
e.preventDefault()

Expand Down Expand Up @@ -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()
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/places_controller.rb
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion app/views/places/index.html.erb
Expand Up @@ -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>

0 comments on commit 2fee561

Please sign in to comment.