I have a table called routes within my database where each route has an origin and destination.
Given any origin, I want to be able to return a list of destinations that can be reached directly from this origin OR from any destination that links with this origin.
How can I do this in Ruby?
def find_available_routes(origin)
routes = Array.new
#each row in routes has 'origin' and 'destination'
end
You mean essentially any destination that can be reached with at most one “layover”?
This won’t exactly be fast, but depending on the needs of your application, it should be acceptable. Caching would be a simple option.