Skip to content

Instantly share code, notes, and snippets.

@alexdunae
Created April 8, 2015 21:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexdunae/3a67633ac2dc4ab06f5b to your computer and use it in GitHub Desktop.
Save alexdunae/3a67633ac2dc4ab06f5b to your computer and use it in GitHub Desktop.
raph
# /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