August 2025
Intermediate to advanced
270 pages
6h 16m
English
Our native map is now rendering beautifully and routing at the right time. But it still hardcodes the marker’s name and coordinate, which isn’t useful. Let’s change that by dynamically pulling in data based on the hike.
Back in the Rails app, create a new view at app/views/maps/show.json.jbuilder. This view will render whenever we hit /hikes/:id/map.json. With the help of Jbuilder, we can extract the hike’s coordinates in a single line of code:
| | json.extract! @hike, :name, :latitude, :longitude |
Go ahead and visit http://localhost:3000/hikes/1/map.json in your browser, and you’ll see the following JSON response:
| | { |
| | "name":"Crystal Springs", |
| |
Read now
Unlock full access