Skip to content

Instantly share code, notes, and snippets.

@ornerymoose
Created March 27, 2012 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ornerymoose/2220119 to your computer and use it in GitHub Desktop.
Save ornerymoose/2220119 to your computer and use it in GitHub Desktop.
Error Message: nil cannot be coerced into float
def show
@textbook = Textbook.find(params[:id])
@this_user = User.find_by_id(session[:user_id])
@textbook.user_textbook_statuses.each do |attribute|
@map = Map.new(:to_location_id => attribute.user.location_id, :from_location_id =>
@this_user.location_id)
@from_address = @map.from_location.as_json(:only => [:latitude, :longitude])
@to_address = @map.to_location.as_json(:only => [:latitude, :longitude])
@distance = Haversine.distance(@from_address['latitude'],
@from_address['longitude'],
@to_address['latitude'],
@to_address['longitude'])
@map.update_attributes(:distance => @distance)
@map.save
locations = [ @from_address, @to_address ]
new_locations = locations.map do |marker| { lng: marker['longitude'], lat: marker['latitude']
}
end
@map = [new_locations]
@location = @map.to_json
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment