Create a new application

rails new explorcity

Let create  two models ie City and Destination. City has an attribute  name. Destination has attributes like  name, latitude, longitude and city_id.

Let us go ahead and scaffold the two models

rails generate scaffold City name:string
rails generate scaffold Destination name:string latitude:float longitude:float city_id:integer

Creating the tables

rake db:migrate

Add Associations



Create a couple of cities and destinations and associate the data. We want to have markers of destinations on city’s show page.


Google Maps API

  1. Visit for web API
  2. We want to embed maps onto our view file. For that visit
  3.  iframe
  4. The above code will embed destination on our app. It takes latitude and longitude as queries
  5. As the API mentions, we need an API key. For the API key, you need to sign in with your Google Account
  6. To create, receive and enable the API key, visit
  7. Create a new project, enable the Google Maps API
  8. The following code specifies the destinationmap
  9. This is how you embed a Map inside Rails applicationmap1