Created
April 8, 2015 21:35
-
-
Save alexdunae/3a67633ac2dc4ab06f5b to your computer and use it in GitHub Desktop.
raph
This file contains hidden or 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
# /waiters/tables_calling.json | |
# in the controller | |
# | |
# you want an array of table IDs as the output | |
def tables_calling | |
calling = [] | |
@tables.where(calling: true).each do |table| | |
calling << table.id | |
end | |
respond_to do |format| | |
format.json { | |
render json: calling | |
} | |
end | |
end | |
# in your view | |
<div id='table-<%= table.id %>' class='table'> | |
</div> | |
# in your javascript | |
function updateTables() { | |
$.getJSON('/waiters/tables_calling.json', function (data) { | |
$('.table').removeClass('calling') | |
for tableNumber in data { | |
$('#table-' + tableNumber).addClass('calling') | |
} | |
}); | |
} | |
window.setTimeout(updateTables, 5000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment