Created
March 9, 2023 15:18
-
-
Save luismendes070/c660f3661ce7251606369e75a306dc93 to your computer and use it in GitHub Desktop.
dreams-map-postgres-ruby-on-rails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rails new dreams_map --database=postgresql | |
rails generate model Dream title:string description:text latitude:float longitude:float | |
rails db:migrate | |
rails generate controller Dreams | |
class DreamsController < ApplicationController | |
def index | |
@dreams = Dream.all | |
end | |
end | |
<div id="map"></div> | |
<script> | |
var map = L.map('map').setView([51.505, -0.09], 13); | |
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { | |
attribution: '© <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors', | |
maxZoom: 18, | |
}).addTo(map); | |
<% @dreams.each do |dream| %> | |
L.marker([<%= dream.latitude %>, <%= dream.longitude %>]).addTo(map) | |
.bindPopup("<b><%= dream.title %></b><br><%= dream.description %>"); | |
<% end %> | |
</script> |
Author
luismendes070
commented
Mar 9, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment