Created
October 23, 2010 15:46
-
-
Save dmclark/642343 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DirectionsController < ApplicationController | |
def new | |
@direction = Direction.new | |
@venues = Venue.all | |
end | |
def create | |
@direction = Direction.new(params[:direction]) | |
if @direction.valid? | |
# TODO send direction here | |
flash[:notice] = "go" | |
redirect_to get_directions_path( params[:direction][:startpoint], | |
params[:direction][:endpoint] ) | |
end | |
respond_to do |format| | |
format.html { render :action => 'new' } | |
format.js | |
end | |
end | |
def show | |
@start = Venue.find(params[:start]).location | |
@destination = Venue.find(params[:destination]).location | |
xml = GoogleDirections.new(@start,@destination).xml | |
doc = Nokogiri::XML(xml) | |
@total_distance = doc.xpath('/distance').text.html_safe | |
@directions = doc.xpath('//step').map do |i| | |
{'description' => i.xpath('html_instructions').text.html_safe, | |
'distance' => i.xpath('distance/text').text.html_safe | |
} | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment