Trying to get my head around nested routes for the following example:
I have a site with the following urls:
router.ex looks like:
scope "/", RestaurentWeb do pipe_through :browser # to handle localhost/region/usa/city/nyc/restaurant resources "region", RegionController do resources "city", CityController do resources "restaurant", RestaurantController do post "/book", BookingController, :book_table end end end # to handle localhost/region/usa/restaurant resources "region", RegionController do resources "restaurant", RestaurantController do post "/book", BookingController, :book_table end end end
Let’s say I get down to
region/city, and I have a standard HTML template for
:show action of Restaurant with a link to book a table which takes me to, say,
restaurant/1234-restaurant-name/book, so in the
show.html.eex template there is a link that looks like
<%= link "Book table", to: Routes.region_city_restaurant_book_path(..) %>
Now, I would like to render the same show template when I am under /region for the same restaurant, but in this case I would need to have a link with
Is there a way to use
Routes and set it up to go to
/book so the link to-path can change dynamically from “where I am” in the url?
Is seems I cannot do this as all
Routes.path begin with “/” and is scoped from the root (i.e. localhost in this case), so is my only option to parse and do string splitting on the path?