-
Notifications
You must be signed in to change notification settings - Fork 8
Asynchronous External Content
JP Barbosa edited this page Jan 21, 2016
·
3 revisions
nano app/views/layouts/application.html.erb
...
<div id="navbar">
<ul class="nav navbar-nav">
<%= link_to('Rails Apz', '/', class: 'navbar-brand') %>
<li><%= link_to('Articles', articles_path) %></li>
<li><%= link_to('Authors', authors_path) %></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<p id="weather" class="navbar-text">Loading weather...</p>
</ul>
</div>
...
open http://openweathermap.org/appid#get
nano app/assets/javascripts/application.js
...
ready = function() {
...
weather();
}
$(document).ready(ready);
$(document).on('page:load', ready);
function weather() {
url = 'http://api.openweathermap.org/data/2.5/weather?q=Sao_Paulo,br&units=metric&APPID=YOUR_API_ID'
$.getJSON(url, function(data) {
$('#weather').html('Sao Paulo: ' + data.main.temp + ' Celsius');
});
}
open http://localhost:3000
git add .
git commit -m "Add asynchronous external content"